#JSON To Rust Structs
Explore tagged Tumblr posts
a-tools · 3 months ago
Text
Tumblr media
JSON To Type Generator is a code convert tool for generating types from JSON data for Golang, Rust, Kotlin and TypeScript. I.e. you just give it some JSON data, and it gives you the type definitions necessary to use that JSON in a program.
0 notes
this-week-in-rust · 2 months ago
Text
This Week in Rust 598
Hello and welcome to another issue of This Week in Rust! Rust is a programming language empowering everyone to build reliable and efficient software. This is a weekly summary of its progress and community. Want something mentioned? Tag us at @thisweekinrust.bsky.social on Bluesky or @ThisWeekinRust on mastodon.social, or send us a pull request. Want to get involved? We love contributions.
This Week in Rust is openly developed on GitHub and archives can be viewed at this-week-in-rust.org. If you find any errors in this week's issue, please submit a PR.
Want TWIR in your inbox? Subscribe here.
Updates from Rust Community
Official
Announcing rustup 1.28.2
Project/Tooling Updates
Announcing Malai - Share your dev server (and more) over P2P
Streaming data analytics, Fluvio 0.17.2 release
Leptos v0.8.0
This Month in Redox - April 2025
Observations/Thoughts
Automatic interleaving of high-level concurrent operations
Flattening Rust's Learning Curve
The Evolution of Rust
std::mem is... interesting
[audio] Svix with Tom Hacohen
Rust Walkthroughs
Authentication with Axum
Newtyped Indices are Proofs
What is my fuzzer doing?
A Rust API Inspired by Python, Powered by Serde
How to create small and secure Docker images for Rust (FROM scratch)
[video] Rust + SQLite: Complete Tutorial (Schema, CRUD, JSON & Async)
Research
An Interactive Debugger for Rust Trait Errors
RustAssistant: Using LLMs to Fix Compilation Errors in Rust Code
Miscellaneous
Memory-safe sudo to become the default in Ubuntu
How To Get A Rust Job Part I: Companies Already Using Rust
GOSIM Spotlight Finalists at RustWeek
Crate of the Week
This week's crate is structstruck, a proc-macro crate for enabling nested struct/enum definitions.
Thanks to Julius Michaelis for the self-suggestion!
Please submit your suggestions and votes for next week!
Calls for Testing
An important step for RFC implementation is for people to experiment with the implementation and give feedback, especially before stabilization.
If you are a feature implementer and would like your RFC to appear in this list, add a call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
No calls for testing were issued this week by Rust, Rust language RFCs or Rustup.
Let us know if you would like your feature to be tracked as a part of this list.
RFCs
Rust
Rustup
If you are a feature implementer and would like your RFC to appear on the above list, add the new call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
Call for Participation; projects and speakers
CFP - Projects
Always wanted to contribute to open-source projects but did not know where to start? Every week we highlight some tasks from the Rust community for you to pick and get started!
Some of these tasks may also have mentors available, visit the task page for more information.
* Hyperswitch - Move connector-specific utility functions to respective connector modules * Hyperswitch - Refactor ACI connector to reuse utilities from utils.rs * Hyperswitch - Analyze and remove unused functions in connector/utils.rs * rama - add ffi/rama-rhai: support ability to use services and layers written in rhai * rama - support (TLS) peetprint in rama-net fingerprinting * rama - support akamai h2 passive fingerprint and expose in echo + fp services * rama - add into_stream to BodyExtractExt trait
If you are a Rust project owner and are looking for contributors, please submit tasks here or through a PR to TWiR or by reaching out on X (formerly Twitter) or Mastodon!
CFP - Events
Are you a new or experienced speaker looking for a place to share something cool? This section highlights events that are being planned and are accepting submissions to join their event as a speaker.
No Calls for papers or presentations were submitted this week.
If you are an event organizer hoping to expand the reach of your event, please submit a link to the website through a PR to TWiR or by reaching out on X (formerly Twitter) or Mastodon!
Updates from the Rust Project
447 pull requests were merged in the last week
Compiler
handle paren in macro expand for let-init-else expr
implement or-patterns for pattern types
initial support for dynamically linked crates
mir-opt: execute MatchBranchSimplification after GVN
refactor rustc_on_unimplemented's filter parser
perf: optimize the codegen for Span::from_expansion
perf: delay checking of #[rustc_no_implicit_autorefs] in autoref lint
perf: simplify LazyAttrTokenStream
perf: use a closure instead of three chained iterators
transmutability: merge contiguous runs with a common destination
transmutability: uninit transition matches unit byte only
Library
avoid redundant WTF-8 checks in PathBuf
delegate to inner vec::IntoIter from env::ArgsOs
implement Iterator::last for vec::IntoIter
stabilize ptr::swap_nonoverlapping in const
stabilize select_unpredictable
streamline the format macro
Cargo
cargo add: suggest similarly named features
in package-workspace, keep dev-dependencies if they have a version
Rustdoc
fix doctest heuristic for main fn wrapping
Rustfmt
also allow bool literals as first item of let chain
Clippy
don't warn about unloaded crates
fix collapsible_if false positive on block stmt before expr
fix manual_unwrap_or_default false positive on ref binding
fix: manual_slice_fill false positive on IndexMut overload
fix: unused_async false positive on default impl
gate collapsible_if let_chains lints on edition 2024 and MSRV
Rust-Analyzer
add PGO support to install
better handle parallelism in cache priming
disable fixpoint for variance computation temporarily
add an assist to unwrap a type with a generic arg
correct assoc ty bound var starting index
correct span info for mir::Operand
don't panic on some weird code
fix move_bounds assists not working for lifetimes
fix incorrect handling of unresolved non-module imports in name resolution
fix proc-macro API creating malformed negative literals
implement mut to const ptr cast for method resolution
improve parser recovery a bit
negative nums in concat! expansion
remove unnecessary token length check for macros in renaming
improve the let code snippet
render more lifetimes
support environment variable CARGO_MANIFEST_PATH
Rust Compiler Performance Triage
A relatively noisy week due to addition of new benchmarks as part of our 2025 benchmark update, and a number of large regressions in a rollup landing late in the week (and so not yet investigated).
Triage done by @simulacrum. Revision range: 25cdf1f6..62c5f58f
2 Regressions, 2 Improvements, 6 Mixed; 3 of them in rollups 31 artifact comparisons made in total
Full report here.
Approved RFCs
Changes to Rust follow the Rust RFC (request for comments) process. These are the RFCs that were approved for implementation this week:
No RFCs were approved this week.
Final Comment Period
Every week, the team announces the 'final comment period' for RFCs and key PRs which are reaching a decision. Express your opinions now.
Tracking Issues & PRs
Rust
Temporary lifetime extension through tuple struct and tuple variant constructors
Stabilize the avx512 target features
Make missing_fragment_specifier an unconditional error
Error on recursive opaque ty in HIR typeck
Add std::io::Seek instance for std::io::Take
remove intrinsics::drop_in_place
Stabilize tcp_quickack
Change the desugaring of assert! for better error output
[Tracking Issue for non_null_from_ref](https://github.com/rust-lang/rust/issues/130823)
Make well-formedness predicates no longer coinductive
Fix parameter order for _by() variants of min / max/ minmax in std::cmp
Finalize repeat expr inference behaviour with inferred repeat counts
Implement (part of) ACP 429: add DerefMut to Lazy[Cell/Lock]
Other Areas
Cargo
Stabilize doctest-xcompile
Rust RFCs
RFC: map_or_default in Option and Result
No Items entered Final Comment Period this week for Language Reference, Language Team or Unsafe Code Guidelines.
Let us know if you would like your PRs, Tracking Issues or RFCs to be tracked as a part of this list.
New and Updated RFCs
RFC: enable derive(From) for single-field structs
#![register_{attribute,lint}_tool]
RFC: Add an attribute for raising the alignment of various items
Upcoming Events
Rusty Events between 2025-05-07 - 2025-06-04 🦀
Virtual
2025-05-07 | Virtual (Indianapolis, IN, US) | Indy Rust
Indy.rs - with Social Distancing
2025-05-07 | Virtual (Rotterdam, NL) | Bevy Game Development
Bevy Meetup #10
2025-05-08 | Virtual (Berlin, DE) | Rust Berlin
Rust Hack and Learn
2025-05-08 | Virtual (Girona, ES) | Rust Girona
Sessió setmanal de codificació / Weekly coding session
2025-05-08 | Virtual (Tel Aviv-Yafo, IL) | Rust 🦀 TLV
שיחה חופשית ווירטואלית על ראסט
2025-05-08 | Virtual (Zürich, CH) | Rust Zürisee
🦀 Celebrating 10 years of Rust 1.0 (co-event with berline.rs) 🦀
2025-05-10 | Virtual | Leptos Community
Leptos Meetup: 0.8 Release and Server Fn Websockets Demo
2025-05-11 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-05-11 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-05-13 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Second Tuesday
2025-05-15 | Hybrid (Redmond, WA, US) | Seattle Rust User Group
May, 2025 SRUG (Seattle Rust User Group) Meetup
2025-05-15 | Virtual (Joint Meetup, Europe + Israel) | Rust Berlin, Rust Paris, London Rust Project Group, Rust Zürisee, Rust TLV, Rust Nürnberg, Rust Munich, Rust Aarhus, lunch.rs
🦀 Celebrating 10 years of Rust 1.0 🦀
2025-05-15 | Virtual (Girona, ES) | Rust Girona
Sessió setmanal de codificació / Weekly coding session
2025-05-18 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-05-19 | Virtual (Tel Aviv-Yafo, IL) | Rust 🦀 TLV
Tauri: Cross-Platform desktop applications with Rust and web technologies
2025-05-20 | Virtual (London, UK) | Women in Rust
Threading through lifetimes of borrowing - the Rust way
2025-05-20 | Virtual (Tel Aviv, IL) | Code Mavens 🦀 - 🐍 - 🐪
Rust at Work a conversation with Ran Reichman Co-Founder & CEO of Flarion
2025-05-20 | Virtual (Washington, DC, US) | Rust DC
Mid-month Rustful
2025-05-21 | Hybrid (Vancouver, BC, CA) | Vancouver Rust
Rust Study/Hack/Hang-out
2025-05-22 | Virtual (Berlin, DE) | Rust Berlin
Rust Hack and Learn
2025-05-22 | Virtual (Girona, ES) | Rust Girona
Sessió setmanal de codificació / Weekly coding session
2025-05-25 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-05-25 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-05-27 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Fourth Tuesday
2025-05-27 | Virtual (Tel Aviv, IL) | Code Mavens 🦀 - 🐍 - 🐪
Rust at Work - conversation with Eli Shalom & Igal Tabachnik of Eureka Labs
2025-05-29 | Virtual (Nürnberg, DE) | Rust Nuremberg
Rust Nürnberg online
2025-06-01 | Virtual (Dallas, TX, US) | Dallas Rust User Meetup
Rust Readers Discord Discussion: Async Rust
2025-06-04 | Virtual (Indianapolis, IN, US) | Indy Rust
Indy.rs - with Social Distancing
Asia
2025-05-17 | Delhi, IN | Rust Delhi
Rust Delhi Meetup #10
2025-05-24 | Bangalore/Bengaluru, IN | Rust Bangalore
May 2025 Rustacean meetup
Europe
2025-05-07 | Girona, ES | Rust Girona
Rust Girona Hack & Learn 05 2025
2025-05-07 | Köln, DE | Rust Cologne
Rust in May: FFI
2025-05-07 | Madrid, ES | MadRust
VII Lenguajes, VII Perspectivas, I Problema
2025-05-07 | Oxford, UK | Oxford Rust Meetup Group
Oxford Rust and C++ social
2025-05-08 | Gdansk, PL | Rust Gdansk
Rust Gdansk Meetup #8
2025-05-08 | London, UK | London Rust Project Group
Adopting Rust (Hosted by Lloyds bank)
2025-05-12 | Amsterdam, NL | RustNL
Bowling at Rust Week
2025-05-12 | Amsterdam, NL | RustNL
Create your rusty steel Rust logo!
2025-05-12 | Amsterdam, NL | RustNL
Walking Tour around Utrecht - Monday (afternoon)
2025-05-12 | Amsterdam, NL | RustNL
Walking Tour around Utrecht - Monday
2025-05-13 | Amsterdam, NL | RustNL
RustWeek 2025 announcement
2025-05-13 - 2025-05-17 | Utrecht, NL | Rust NL
RustWeek 2025
2025-05-14 | Reading, UK | Reading Rust Workshop
Reading Rust Meetup
2025-05-15 | Oslo, NO | Rust Oslo
Rust 10-year anniversary @ Appear
2025-05-16 | Amsterdam, NL | RustNL
Rust Week Hackathon
2025-05-16 | Utrecht, NL | Rust NL Meetup Group
RustWeek Hackathon
2025-05-17 | Amsterdam, NL | RustNL
Walking Tour around Utrecht - Saturday
2025-05-20 | Aarhus, DK | Rust Aarhus
Hack Night - Robot Edition
2025-05-20 | Leipzig, SN, DE | Rust - Modern Systems Programming in Leipzig
Topic TBD
2025-05-22 | Augsburg, DE | Rust Augsburg
Rust meetup #13
2025-05-22 | Bern, CH | Rust Bern
2025 Rust Talks Bern #3 @zentroom
2025-05-22 | Paris, FR | Rust Paris
Rust meetup #77
2025-05-22 | Stockholm, SE | Stockholm Rust
Rust Meetup @UXStream
2025-05-27 | Basel, CH | Rust Basel
Rust Meetup #11 @ Letsboot Basel
2025-05-29 | Oslo, NO | Rust Oslo
Rust Hack'n'Learn at Kampen Bistro
2025-06-04 | München, DE | Rust Munich
Rust Munich 2025 / 2 - Hacking Evening
2025-06-04 | Oxford, UK | Oxford Rust Meetup Group
Oxford Rust and C++ social
North America
2025-05-07 | Chicago, IL, US | Chicago Rust Meetup
Rust Happy Hour
2025-05-08 | México City, MX | Rust MX
Calculando con el compilador: Compiler time vs Run time. Introducción a uv
2025-05-08 | Portland, OR, US | PDXRust
Apache DataFusion: A Fast, Extensible, Modular Analytic Query Engine in Rust
2025-05-11 | Boston, MA, US | Boston Rust Meetup
Porter Square Rust Lunch, May 11
2025-05-13 | New York, NY, US | Rust NYC
Multi-Platform App in Rust @ Warp.dev && Verifying Rust's Stdlib @ CMU
2025-05-15 | Mountain View, CA, US | Hacker Dojo
RUST MEETUP at HACKER DOJO
2025-05-15 | Nashville, TN, US | Music City Rust Developers
Using Rust For Web Series 2 : Why you, Yes You. Should use Hyperscript!
2025-05-15 | Hybrid (Redmond, WA, US) | Seattle Rust User Group
May, 2025 SRUG (Seattle Rust User Group) Meetup
2025-05-20 | San Francisco, CA, US | San Francisco Rust Study Group
Rust Hacking in Person
2025-05-21 | Hybrid (Vancouver, BC, CA) | Vancouver Rust
Rust Study/Hack/Hang-out
2025-05-28 | Austin, TX, US | Rust ATX
Rust Lunch - Fareground
2025-05-29 | Atlanta, GA, US | Rust Atlanta
Rust-Atl
South America
2025-05-28 | Montevideo, DE, UY | Rust Meetup Uruguay
Primera meetup de Rust de 2025!
2025-05-31 | São Paulo, BR | Rust São Paulo Meetup
Encontro do Rust-SP na WillBank
If you are running a Rust event please add it to the calendar to get it mentioned here. Please remember to add a link to the event too. Email the Rust Community Team for access.
Jobs
Please see the latest Who's Hiring thread on r/rust
Quote of the Week
Well, the answer is basically yes. Our firmware is all Rust. Every component of our autonomy stack is Rust. Our app is 50% in Rust. And, our visualization tools are in Rust. Our production tools are in rust. The production QC software, which we ship to China, is in rust. Our internal websites are in rust. It's rust all over. We’ve drank the Rust Kool-Aid. In fact, there is no Python installed on the robots. This is not to dis Python at all, but it’s just simply not there.
We use Python for neural network training. But Python is boxed to that. Everything else is Rust. And, the advantage of using Rust exponentially builds up.
– Vivek Bagaria on filtra.io
Thanks to Brian Kung for the suggestion!
Please submit quotes and vote for next week!
This Week in Rust is edited by: nellshamrell, llogiq, cdmistman, ericseppanen, extrawurst, U007D, joelmarcey, mariannegoldin, bennyvasquez, bdillo
Email list hosting is sponsored by The Rust Foundation
Discuss on r/rust
1 note · View note
codecraze · 2 years ago
Text
TCP Server Rust
This is a Rust program that sets up a TCP server to listen for incoming client connections on port 5566. When a client connects to the server and sends a JSON string representing an Employee object, the server deserializes the JSON string and prints the employee's first name to the console.
Here's a breakdown of the code:
The use statements at the top of the file import the necessary Rust modules and dependencies. The serde module is used for serializing and deserializing data, and the std::io and std::net modules are used for handling I/O and network connections.
The Employee struct is defined with three fields: first_name, last_name, and employee_id. The #[derive(Serialize, Deserialize)] attribute macros are used to generate the serde implementations for the struct, which allow it to be serialized and deserialized to and from JSON.
The main function sets up a TCP server using the TcpListener struct and listens for incoming client connections on port 5566. When a client connection is received, a new thread is spawned to handle the connection.
The process_object function is called in the new thread to handle the client connection. The function reads the incoming data from the client, deserializes the JSON string to an Employee object, and prints the employee's first name to the console.
The program uses the try_clone method to create a new handle to the same stream, which allows the function to read the incoming data without consuming the original stream.
The program uses Rust's Result type to handle errors that may occur during I/O operations or JSON deserialization.
Overall, this code demonstrates how to set up a TCP server in Rust and handle incoming client connections, as well as how to serialize and deserialize data to and from JSON using the serde library.
Here is main.rs
Tumblr media Tumblr media
Here is Cargo.toml
Tumblr media
Run the following command in your project directory to build and run the server:
cargo run
Open a new terminal window and connect to the server using a TCP client, such as netcat or telnet. For example, you can run the following command to connect to the server:
telnet 127.0.0.1 5566
Once connected, you can send a message or object to the server. For example, to send a message, simply type a string and press Enter. The server will respond with an acknowledgement message.
To send an object, create a JSON string representing an Employee object and send it to the server using the same connection. The server will deserialize the JSON string and print the employee's first name.
To stop the server, press Ctrl+C in the terminal window where the server is running.
2 notes · View notes
idein-inc · 5 years ago
Text
AWSで使うRust
κeenです。この記事では IdeinでのAWSの利用例の開示の一環として、どのようにRustをAWS上で動かしているかをご紹介します。
Ideinの提供しているサービスActcastではサーバの主たる部分をRustで書いています。 はじめの頃は本当にRustだけだったのですが、各方面に秀でたメンバーが集まった結果、今ではHaskellやTypeScript、一部ですがGoも動いています。
そもそもRustの採用事例が少ないことからRustをAWSで扱う知見はそこまで多くなさそうです。 そこで今回はIdeinでどのようにAWS上でRustを動かしているか、動かすにあたって必要だった知見などを紹介していきます。
���体像
全体の中で、Rustが動いている環境はECSとLambdaです。 ECSで動いているのはActcastのバックエンドAPIで、Actcastのサーバ本体とも言える部分です。
Lambdaの方は全部で4つあります。 起動トリガで分類するとAPI GatewayのAuthorizerとHandlerに1つづつ、CloudWatch EventsのEventとTimerに1つづつです。
Tumblr media
Actcastでは今のところAWSの構成を全てterraformで管理しているのでECSジョブやLambdaもterraformからデプロイしています。 これについてはサービスリリースを乗り越えたので構成の見直しを予定しています。
ECSはdockerコンテナさえ作ってしまえば大きな懸念なく動くので以下ではLambdaでの動かしかたについて紹介します。
コード
使っているライブラリやコーディング上のテクニックを紹介します。
全般
Lambdaランタイム
LambdaのRustランタイムはありません。 しかしカスタムランタイムを使えばRustを動かすことができます。 カスタムランタイムでRustを動かすためのライブラリも公開されています。 このライブラリ(lambda-runtime)を使えばエントリポイント( main 関数)だけLambda用に作ってあげれば動くのでコードの残りの部分はあまりLambdaについて気にしなくてよくなります。 別の言い方をするとLambda特有の処理は全てエントリポイント部分に集約しています。 つまり、 main 関数の見た目は以下のようになっています。
use tokio::runtime::current_thread::block_on_all; use app::{api, App}; pub async fn handle( app: &App, event: api::CustomEvent, _ctx: Context, ) -> Result { app.do_something_with_event(event, hoge, fuga) // do other things... } fn main() { /* 初期化のコード */; let app = App::new(...); lambda!(|req, ctx| { block_on_all(handle(&app, req, ctx)) }) }
コードを少し解説すると以下のようになっています。
Lambdaのランタイムは何度か使われるので Appはメインループの外で作って使い回す
lambda! マクロでLambdaのメインループに入る
リクエストとレスポンスはserdeの Deserialize/Serialize を実装した型を書いておけ��JSONから変換される
Futureを走らせるために block_on_all を呼んでいる
このうち3と4についてもう少し詳しく触れます。
出入力フォーマット
リクエストとレスポンスはAWSのドキュメントを読んで、自分の欲しいフィールドを扱えるようなデータ型を定義します。例えばAPI GatewayのCustom Authorizerであれば以下のようなデータ型を定義しています。
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize)] #[serde(rename_all = "camelCase")] pub struct CustomEvent { #[serde(rename = "type")] pub type_: String, pub authorization_token: String, pub method_arn: String, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "camelCase")] pub struct CustomOutput { pub principal_id: String, pub policy_document: PolicyDocument, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "PascalCase")] pub struct PolicyDocument { pub version: String, pub statement: Vec, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "PascalCase")] pub struct Statement { pub action: String, pub effect: Effect, pub resource: String, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(rename_all = "PascalCase")] pub enum Effect { Allow, Deny, }
少し冗長ですが実行時にエラーが出るよりはマシなので1つ1つ丁寧にデータ型を定義しています。
同期と非同期
我々のコードは全て非同期で書かれていますが(cf プロダクションのRustコードを async / await に移行した話)lambda_runtimeは非同期サポートをしていないので明示的にブロックする必要があります。 非同期サポートが欲しいというissueはあるのですが、進捗芳しくないみたいです。 ここは期待せずにブロックするコードを書きましょう。
コード構成
コード構成はLambda依存の部分とビジネスロジックを完全に切り離しています。 具体的にはCargoのWorkspaceの機能を使ってコアとなるビジネスロジック部分と、それに依存するECSやLambdaのエントリポイント部分のパッケージを分けて��ます。 他にも外部(RDBやその他のAWSリソース)とのやりとりもパッケージを分けていますがこれは普通の書き方ですね。
Rusoto
Lambdaで完結することは少なくて、他のAWSサービス群を利用しています。 RustからAWSサービス群を利用するのにはRusotoを使っています。 過去には機能が足りなくてPull-Requestを送ることもありますが、最近はおおむねそのまま使えています。
ただしasync/await対応(とそれに伴なう依存ライブラリのアップデート)がまだなのでasync/await移行してしまった我々のコードベースからは少し使いづらいものがあります。 これについてはPull-Requestが出ていますがマージされるまでもう少し掛かりそうです。 これらのPRがマージされ次第我々もRusotoを使っている部分を async/await に書き換えていく予定です。 本当はRusotoの依存ライブラリが他の依存ライブラリとコンフリクトしてバージョンの更新がブロックしているなどの問題も発生してりるので、 async / await 対応以外の更新もありますがそれはまた別の話。
DLL
Rusotoを使う際にSSLライブラリが依存に入ります。これについて注意点があります。 詳しくはビルドの節で説明しますがLambda内でopensslを使うのは非常にハードルが高いのです。 なのでLambda内でRusotoを使う際はopensslではなくpure rustのrustlsを使いたいです。 一方でECSなどopensslの使用に差し障りのない場面では枯れたライブラリであるopensslを使いたいです。
そこで、ECSでもLambdaでも使われるコアロジック部分は以下のようにopensslでもrustlsでも動くように作っています。
# Cargo.toml [dependencies] hyper = "0.12" # hyper-rustlsとhyper-tlsをoptionalにしておく hyper-rustls = { version = "0.16", optional = true } hyper-tls = { version = "0.3", optional = true } rusoto_core = { version = "0.40", default_features = false } rusoto_credential = "0.40" rusoto_ecr = { version = "0.40", default_features = false } [features] # featureで全体のtlsを切り替えられるようにしておく default = ["native-tls"] native-tls = ["hyper-tls", "rusoto_core/native-tls", "rusoto_ecr/native-tls"] rustls = ["hyper-rustls", "rusoto_core/rustls", "rusoto_ecr/rustls"]
// src/lib.rs // Rustのコード内では有効にされた方を使うようにしておく #[cfg(feature = "hyper-rustls")] use hyper_rustls as tls; #[cfg(feature = "hyper-tls")] use hyper_tls as tls;
上記のようにコードとしてはopensslまたはrustlsで動くように作っておいて、使うときに選択するようにしています。
同様にLambdaやECSのエントリポイントとなるパッケージでもフィーチャを用いてどちらでも動くようにしています。 そしてビルドするときに --no-default-features --features rustls などのオプションを渡してopensslとrustlsを使い分けています。
本当はビルド時ではなくエントリポイントの Cargo.toml 時点でフィーチャを固定したかったのですがそれは難しいようでした。 hyper-tls を有効にするECSのコードと hyper-rustls を有効にするLambdaのコードが混在する状況でワークスペースのビルド (cargo build 相当)をするとどちらのフィーチャも有効になってしまい、ビルドに失敗します。 もうちょっと言うと cargo check や cargo test もままならなくなってしまうので大変不便です。 一応、個別のパッケージ毎のビルド(cargo build -p package 相当)ではフィーチャが混在しなくなるので成功するものの、エディタ/IDEの設定ではデフォルトで -p オプションが付かないものが多いので何もせずに使える方式にしたいです。 なのでデフォルトを全て hyper-tls に寄せてしまい、Lambdaのコードをビルドするときだけ rustls を使うようにしました。
もう1つ、Lambda内からPostgreSQLにもアクセスしています。PostgreSQLを使うためにlibpqに依存しています。 これについてはビルド時に頑張ってLambda内からも使えるようにしてますので、ビルドの節を参照して下さい。
HTTP
RustでLambdaを使うときの一般論としては前項の通りですが、ALBやAPI GatewayのハンドラとしてのLambdaを使うときはもう少しライブラリのサポートがあります。 具体的にはlambda-httpクレートが用意されています。
Actcastでlambda-httpを使っているのは比較的アクセスの少ないAPIで、メインとなるエンドポイント1つとそれに付随するエンドポイント数個からなります。 小用にいくつもLambdaを作るのも管理が大変ですし、cold start問題もあります。 そこで1つのLambdaで全てのエンドポイントを処理しています。 そのLambdaではルーティングに以下のようにHTTPメソッドとリソースパスを match 式に掛けています。
let (http_method, resource_path) = match request.request_context() { RequestContext::ApiGateway { http_method, resource_path, authorizer, .. } => (http_method, resource_path), _ => unreachable!(), }; match (http_method.as_str(), resource_path.as_str()) { ("GET", "/path1") => { // ... } ("GET", "/path1/{some_id}") => { let some_id = request.get_id("some_id")?; // ... } ("POST", "/path2/{other_id}/hoge") => { let other_id = request.get_id("other_id")?; // ... } ("POST", "/path2/{other_id}/fuga") => { let other_id = request.get_id("other_id")?; // ... } _ => unreachable!(), }
マッチ対象が多くなると破綻しそうですが目で数を数えられるくらいの範囲なら問題ないでしょう。
ビルド
ECS
少しだけECSのビルドに触れておきます。
基本的にはビルドと実行のベースコンテナされ揃えればバイナリをコピーしてあげるだけで動きます。 ほとんど大したことをしないのにDockerfileを管理するのが面倒なので cargo-pack-dockerというツールを作ってCargoだけでパッケージングまで済むようにしています。
Lambda
Lambda内で動かすバイナリは普段と勝手が違うところが多くあります。 例えば何も気にせずにビルドしたバイナリをLambda環境に持っていって動かすとglibcのバージョンの問題で version `GLIBC_2.27' not found とエラーが出たりします。 また、今回の我々のようにlibpqを使いたい場合もLambdaのランタイムにlibpqが存在しないのでどうにかしないといけません。
glibcやlibpqなどのダイナミックリンクライブラリ(DLL)が上手く使えずに起動に失敗してしまう問題にはおおまかに2つの対策があります
DLLを使わない
DLLを頑張って使う
DLLを使わない
glibcが動かない環境でバイナリを動かしたいときのノウハウは古くからあります。 musl libcを使い、それをバイナリに静的にリンクしてしまえば実行時にlibcのDLLに依存しなくなります。 同様にlibpqについても静的リンクしてしまえば問題が発生しなくなります。
そのためにrust_musl_dockerのようにmusl libcや静的リンク可能なlibpqが入ったビルド用コンテナも用意されています。 このノウハウを使えばLambdaに限らず色々な場所で動かせるようになります。
しかし今回はこの方法は採用しませんでした。 一応libcとしてはglibcとmusl libcは互換性はありますが、実装は別物です。 ���かい部分の挙動やパフォーマンス特性も違うため、glibc環境で開発しているアプリケーション(や、もっと言うと依存ライブラリも)をmusl libcで動かすのは一定のリスクがあります。 それに、今回はglibcが動かない環境という訳ではなくて、ビルド時に使ったglibcと実行時に利用できるglibcのバージョンが異なるだけです。 glibcのバージョンを揃える方向に舵を切ってみます。
DLLを頑張って使う
RustのLambdaランタイムlambda_runtimeのREADMEをよく見るとLambda向けのビルド方法が書かれています。 そこではsoftprops/lambda-rustというdockerコンテナでビルドしています。
このコンテナを詳細に調べると、Lambdaの実行環境と同じバージョンのAmazon Linuxのイメージを使ってRustをビルドしています。 現時点での実行環境のバージョンはドキュメントによると、2018.03.0.20181129-x86_64-gp2 と、いささか古いものになっています。 因みに、今のところRustの動くカスタムランタイムではAmazon Linux 2は使えないようです。
softprops/lambda-rustがそのままビルドに使えたら良かったのですが、残念ながら今回は使えません。 libpq などのライブラリも一緒に使う術が用意されていないからです。
しかし基本となるアイディアはそのまま流用できそうなので使います。 すなわち、以下のような方法を採ります:
Lambdaと互換性のあるAmazon LinuxのDockerイメージを使う
DockerイメージにRustのツールチェーンをインストールする
Dockerイメージにlibpqなどをインストールする
Dockerコンテナ内でRustをビルドし、成果物をZIPにまとめる
Lambdaの実行環境と同じDockerイメージを使いたいのですがどうやらピタリとバージョンの合うDockerイメージが配られているとは限らないようです。 今回は 2018.03.0.20191219.0 を使います。 余談ですがActcastではRaspbianをはじめとしてDebian系のOSを統一して使っています。しかしここだけRedHat系をOSを使っていることになります。
次はlibpqのインストールです。 我々はPostgrSQL 11の機能を使いたいので、libpqもそれに相当するものをインストールしたいです。 しかしAmazon Linuxのイメージが古いためyumではインストールできません。 仕方ないのでPostgreSQL 11のレジストリからlibpqをインストールしています(因みにAmazon Linux2なら yum で入るようです)。
ビルド用のイメージが準備できたとして、次はビルドです。ビルドは概ね以下のようなコマンドで行っています。
$ docker run --rm \ -e CARGO_TARGET_DIR=/tmp/app/your_app/target/lambda \ -v $ROOT_DIR/:/tmp/app \ -v $ROOT_DIR/.cache/cargo/registry:/root/.cargo/registry \ -v $ROOT_DIR/.cache/cargo/git:/root/.cargo/git \ -t your/build_image /tmp/app/build-script.sh your_app
ここで、 $ROOT_DIR はワークスペースのルートを指す変数です。 ポイントで解説すると
ビルド用のイメージ(your/build_image)内でビルドする
ビルド用のスクリプト(build-script.sh)を使ってビルドする(後述)
ワークスペース全体を /tmp/app にマウントする
ワークスペースのルートに .cache/ ディレクトリを作っておき、そこにCargoのキャッシュを持たせる
Cargoのターゲットディレクトリは target/ ではなく target/lambda にしておく
となっています。
4.と5.について補足します。 コンテナ内でビルドするときにもホスト同様ビルドキャッシュは持っておいて欲しいです。 しかしホスト環境とコンテナ環境で同じキャッシュを使うと権限の問題が発生します。 コンテナ内はrootユーザで動作しているのでコンテナ内から作ったキャッシュはrootのものになり、ホストに戻ったときに取り回しが面倒になってしまうからです。 そこでコンテナ内で使うキャッシュとホストのキャッシュを分けることで問題を解決します。 それが .cache/ ディレクトリと target/lambda ディレクトリです。 また、 target/lambda はビルド成果物であるZIPファイルの受け渡し場所としての役割もあります。
さて、次はビルドに使うスクリプト(build-script.sh)です。 概ね以下のようなことをしています。
# ビルド cargo build --release # バイナリ名はbootstrapにしておく cp "$CARGO_TARGET_DIR/release/your_app" bootstrap # bootstrapが動的リンクしているライブラリをlibに入れる。ここでは `pq` 。 mkdir -p lib ldd bootstrap | grep pq | grep -o '=> [^ ]*' | sed 's/=> //' | xargs -I@ cp @ lib/ # bootstrapとlibをまとめてZIPに固める zip -X "$CARGO_TARGET_DIR/release/your_app.zip" bootstrap lib/* rm -rf bootstrap lib
ざっくりいうとビルドしてZIPに固めているだけですが、途中で動的リンクしているライブラリのパスを取得してlibディレクトリに入れています。 これでできあがるZIPファイルは以下のような構造になっています
. ├── bootstrap └── lib └── libpq.so // その他ライブラリ
LambdaのドキュメントによるとZIPの中のlibディレクトリにDLLを入れておくと LD_LIBRARY_PATH が通っているので($LAMBDA_TASK_ROOT/lib)、実行時に参照できるようになります。
これであとはLambdaにデプロイすると期待通りに動いてくれます。 我々のシステムでは今のところTerraformからデプロイしているのでTerraformが target/lambda 以下にあるZIPファイルを参照することになります。
上記の手法はlibpqに依存した箇所はないので原理的にはあらゆるDLLを同じ方法で使えるようになるはずです。 しかし何故かopensslだけは上手くいきませんでした(crypto.oがみつからないとかなんとか…)。 未だに原因が不明なのですが、現時点では前述のとおりrustlsを使って問題を回避しています。
テスト
テストについてはlambda_runtimeのドキュメントに載っている通りのコマンドが使えます。
unzip -o \ target/lambda/release/your_app.zip \ -d /tmp/lambda && \ docker run \ -i -e DOCKER_LAMBDA_USE_STDIN=1 \ --rm \ -v /tmp/lambda:/var/task \ lambci/lambda:provided
これにヒアドキュメントを使って標準入力からJSONを渡し���出力のJSONを得ています。
単体テストはこれで済むのですがインテグレーションテストはもうちょっと複雑なセットアップが必要です。 実を言うとActcastでは今のころローカル環境でのインテグレーションテストをできていません。 Lambdaは総じて多彩なAWSリソースと相互連携しながら動くのでローカルに環境を構築するのが難しいからです。 現在は開発/サンドボックス環境に実際にデプロイして動作確認や自動テストを行っています。
振り返って
RustでLambdaを使いはじめたのはカスタムランタイムとRustのサポートライブラリが発表されて間もない頃でした。 Rustを動かす情報がほとんどない上に私が個人的にLambdaを触ったのがはじめてだったこともあり、手探りで進めていって今の形に落ち着きました。
最初に作ったLambdaはAPI Gatewayの裏で動くHandlerとカスタムAuthorizerでした。 新規開発のAPIということもあり、既存のサーバとはコードベースをほとんど共有せずに作ってLambdaで動かすノウハウを獲得しました。 要するに技術的投資として新しいことを始めたのです。 PostgreSQLに接続しているのもその一環です。 複数のコンポーネントがRDBにアクセスするのはアンチパターンとされていますが、様々な状況判断からこのような選択をとりました。 そのあとに既存のコードを流用しつつ動くLambdaも作っていきました。
これらを振り返ってみます。
RustをLambdaで動かす
おおむね良さそうでした。 最初、正しく動くバイナリをビルドするのに苦戦して時間が掛かりましたが一度作り方を把握しさえしてしまえば大きな懸念なく使えます。
新規コードベースで開発した
どちらかというと良くなさそうでした。 一番最初に既存の複雑性を排して新しい技術に取り組める点は良かったです。 しかしコード(ビジネスロジック)に重複があるなどの問題がありました。 実際、他のメンバーから「最近ここに変更加えたけどLambdaの動作に影響ない?」などの問い合わせが来ることもありました。
それだけでなく、Rustのように強い静的型付言語ではコンパイラがある程度の全体整合性を検査してくれることに強みがあります。 コードベースを分けてしまうとその恩恵に与れなくなってしまいます。 コードの重複の排除だけでなく、一歩進んで積極的な整合性検査のためにもコードベースの統合が必要そうでした。
将来的に現在別のコードベース(別ディレクトリ)になっているものを1つにまとめられたらなと思っています。
まとめ
この記事ではActcastでRustをどのようにAWS上で動かしているかを紹介しました。 これで完璧と言えるものではないですし、エコシステムの今後の発展に期待すべき点もあります。 しかしある程度の規模でRustをAWS上で動かしている例として皆さまの一助になれば幸いです。
さいごに、IdeinではRustでWebサービスを作りたいエンジニアを募集しています!!
6 notes · View notes
tak4hir0 · 5 years ago
Link
キーポイント The Kubernetes API itself empowers cloud native adoption by providing a single integration point for all cloud resources. There are frameworks and libraries to streamline writing an operator. These exist in multiple languages, but the Go ecosystem is the most mature. You can make an operator for software that isn't your own. A devops team might do this to help manage a database or other external product. The hard part isn't the operator itself, but understanding what actions it needs to take. 原文(投稿日:2020/09/25)へのリンク 要約: Operatorは、何年もの間、Kubernetesエコシステムの重要な部分を占めてきました。管理面をKubneretes APIに移動することで、「一枚のガラス」体験が容易になります。Kuberentesネイティブアプリケーションの簡素化を検討している開発者、または既存のシステムの複雑さを軽減しようとしているDevOpsの実践者にとって、Operatorは魅力的な提案になる可能性があります。しかし、どのようにしてスクラッチからOperatorを作成できるのでしょうか ? Operatorの深層 Operatorとは何か ? Operatorは今日どこにでもあります。データベース、クラウドネイティブプロジェクト、Kubernetesでのデプロイやメンテナンスが複雑なものはすべて1つにします。2016年にCoreOSによって最初に導入されたこれらのプロダクトは、運用上の関心事をソフトウェアに移すというアイデアをカプセル化しています。Runbookやその他のドキュメントの代わりに、Operatorはアクションを自動的に実行します。たとえば、Operatorはデータベースのインスタンスをデプロイしたり、データベースのバージョンをアップグレードしたり、バックアップを実行したりできます。そして、これらのシステムをテストし、人間のエンジニアよりも速く反応することができます。 Operatorは、カスタムリソース定義でツールを拡張することにより、ツールの構成をKubenretes APIに移動します。これは、Kubenretes自体が「一枚のガラス」になることを意味します。これにより、DevOpsの実践者は、Kubernetes APIリソースを中心に構築されたツールの豊富なエコシステムを利用して、デプロイされたアプリケーションを管理および監視できます: Kubernetesに組み込まれているロールベースのアクセス制御 (RBAC) を使用した、認証と認可の変更。 「GitOps」を使用したプロダクション環境の変更に対する再現可能なデプロイとコードレビュー。 Open Policy Agent (OPA) に基づくセキュリティツールを使用したカスタムリソースに対するポリシーの適用。 Helm、Kustomize、ksonnet、Terraformなどのツールを使用してデプロイメントの記述を簡素化。 このアプローチにより、プロダクション環境、テスト環境、および開発環境間の同一性を確保すること���できます。それぞれがKubernetesクラスタである場合、Operatorを使用してそれぞれに同じ構成をデプロイできます。 なぜそれを作りたいのでしょうか ? Operatorをスクラッチから作成する理由はたくさんあります。通常、プロダクトのファーストパーティOperatorを作成しているのは開発チームか、サードパーティソフトウェアの管理の自動化を検討しているDevOpsチームです。いずれにせよ、開発プロセスは、Operatorが管理する必要のあるケースを特定することから始まります。 最も基本的なOperatorがデプロイメントを処理します。APIリソースに応答してデータベースを作成することは、kubectl applyと同じくらい簡単です。ただし、これは、StatefulSetsやDeploymentsなどの組み込みのKubernetesリソースよりも少し優れています。Operatorが価値を提供し始めるのは、より複雑な操作です。データベースを拡張したい場合はどうなりますか ? StatefulSetを使用すれば、kubectl scale statefulset my-db --replicas 3を実行でき、3つのインスタンスを取得できます。しかし、それらのインスタンスが異なる構成を必要とする場合はどうなるのでしょうか ? 1つのインスタンスをプライマリとして指定し、他のインスタンスをレプリカとして指定する必要がありますか ? 新しいレプリカを追加する前に必要なセットアップ手順がある場合はどうなるのでしょうか ? この場合、Operatorは特定のアプリケーションを理解した上でこれらの設定を構成できます。 より高度なOperatorは、負荷、バックアップ、リストアに応じた自動スケーリング、Prometheusなどのメトリックシステムとの統合、さらには使用パターンに応じた障害検出や自動チューニングなどの機能を処理できます。従来の「Runbook」ドキュメントがある操作はすべて、自動化、テスト、および自動応答に依存することができます。 管理対象のシステムは、Operatorのメリットを得るためにKubernetesにある必要はありません。たとえば、Amazon Web Services、Microsoft Azure、Google Cloudなどの主要なクラウドプロバイダは、オブジェクトストレージなどの他のクラウドリソースを管理するためのKubenretes Operatorを提供しています。これにより、ユーザーはKubernetesアプリケーションを構成するのと同じ方法でクラウドリソースを構成できます。運用チームは、他のリソースと同じアプローチを取り、Operatorを使用して、APIを介したサードパーティのソフトウェアサービスからハードウェアまで、あらゆるものを管理できます。 Operatorの例 この記事では、etcd-cluster-operatorに焦点を当てます。これは、Kubernetes内でetcdを管理する多くの同僚と一緒にコントリビュートしたOperatorです。この記事は、そのOperatorまたはetcd自体を紹介するようにはデザインされていないため、Operatorが何をしているのかを理解するために知っておく必要があること以外に、etcd操作の詳細については詳しく説明しません。 つまり、etcdは分散型Key-Valueデータストアです。次の場合に限り安定的に管理できます。 各etcdインスタンスには、コンピューティング、ネットワーキング、およびストレージ用の障害が分離されるドメインがある。 各etcdインスタンスには、一意のネットワーク名がある。 各etcdインスタンスは、ネットワーク上の他のすべてのインスタンスに到達できる。 各etcdインスタンスは、他のインスタンスのすべてが通知される。 加えて: etcdクラスターを拡大または縮小するには、インスタンスを追加/削除する前に、etcd管理APIを使用してクラスタへの変更を通知する特定の操作が必要。 バックアップは、etcdの管理APIの「スナップショット」エンドポイントを使用して取得できる。gRPCでヒットすると、バックアップファイルがストリーミングされる。 リストアは、バックアップファイルおよびetcdホストのデータディレクトリでetcdctlツールを使用して実行される。実機では簡単だが、Kubernetesでの調整が必要。 このとおり、管理には、Kubernetes StatefulSetが通常実行できる以上のことがあるため、Operatorに頼ります。etcd-cluster-operatorがこれらの問題を解決するために使用する正確なメカニズムについては詳しく説明しませんが、この記事の残りの部分では、このOperatorを例として参照します。 Operator解剖学 Operatorは次の2つから構成されます: 1つ以上のKubernetesカスタムリソース定義 (CRD)。Kubernetesに、どのフィールドが必要かなど、新しい種類のリソースを記述する。たとえば、etcd-cluster-operatorには、異なる概念をカプセル化するためのEtcdClusterとEtcdPeerの両方があり、複数存在する場合がある。 カスタムリソースを読み取り、それに応じて動作する実行中のソフトウェア。 通常、Operatorはコンテナ化され、サービスを提供するKubernetesクラスタにデプロイされます。通常は単純なDeploymentリソースを使用します。理論的には、Operatorソフトウェア自体は、クラスタのKubernetes APIと通信できる限り、どこでも実行できます。ただし、通常は、管理しているクラスタでOperatorを実行する方が簡単です。通常、これは、Operatorを他のリソースから分離するためのカスタムNamespaceにあります。 この方法を使用してOperatorを実行している場合は、さらにいくつかのものが必要です: Operatorの実行可能ファイルを含む、クラスタで使用可能なコンテナイメージ。 Namespace。 OperatorのServiceAccount。カスタムリソースを読み取り、管理する必要のあるリソース (Podなど) を書き込むためのアクセス許可を付与します。 OperatorコンテナのDeployment。 上記のServiceAccountにバインドするClusterRoleBindingおよびClusterRoleリソース。 Webhook構成。 権限モデルとWebhookについては後で詳しく説明します。 ソフトウェアとツール 最初の質問は言語とエコシステムです。理論的には、HTTP呼び出しを行うことができるほとんどすべての言語を使用してOperatorを作成できます。リソースと同じクラスタにデプロイすると仮定すると、クラスタが提供するアーキテクチャ上のコンテナで実行できる必要があります。通常、これはlinux/x86_64であり、etcd-cluster-operatorが対象としますが、arm64やその他のアーキテクチャ、またはWindowsコンテナ用にOperatorを構築することを妨げるものは何もありません。 Go言語は、一般的に最も成熟したツールを備えていると考えられています。Kubernetesのコアでコントローラを構築するために使用されるフレームワークであるcontroller-runtimeは、スタンドアロンツールとして利用できます。さらに、KubebuilderやOperator SDKなどのプロジェクトは、コントローラランタイムの上に構築され、簡素化された開発エクスペリエンスを提供することを目的としています。 Java、Rust、PythonなどのGo以外の言語に、Kubernetes APIに接続して、Operatorをビルドするための汎用または特化したツールやプロジェクトがあります。これらのプロジェクトは、さまざまなレベルの成熟度とサポートがあります。 もう1つのオプションは、HTTPを介してKubernetes APIと直接対話することです。これは最も手間のかかる作業が必要ですが、チームは最も使いやすい言語を使用できます。 最終的に、この選択は、Operatorを作成および保守するチーム次第です。チームがすでにGoに慣れている場合は、豊富なGoツールが選択を明確にします。チームがまだGoを使用していない場合、学習曲線とより成熟したエコシステムツールのGoを使用するための継続的なトレーニングを犠牲にして、より成熟していないが基礎となる言語に精通しているエコシステムとの間のトレードオフになります。 etcd-cluster-operatorの場合、チームはすでにGoに精通しているため、それは私たちにとって明らかな選択でした。また、Operator SDKではなくKubebuilderを使用することを選択しました、これは既存の知識があるためです。ターゲットプラットフォームはlinux/x86_64でしたが、必要に応じて他のプラットフォーム用にGoを構築できます。 カスタムリソースと望ましい状態 (Desired State) etcd Operator用に、EtcdClusterという名前のカスタムリソース定義を作成しました。CRDがインストールされると、ユーザはEtcdClusterリソースを作成できます。最高レベルのEtcdClusterリソースは、etcdクラスタが存在することを望んでいることを記述し、その構成を提供します。 apiVersion: etcd.improbable.io/v1alpha1 kind: EtcdCluster metadata: name: my-first-etcd-cluster spec: replicas: 3 version: 3.2.28 apiVersion文字列は、これがAPIのバージョン (この場合はv1alpha1) であることを表します。kindはこれをEtcdClusterであると宣言しています。他の多くの種類のリソースと同様に、nameを含める必要があり、namespace、labels、annotations、およびその他の標準アイテムを含めることができるmetadataキーがあります。これにより、EtcdClusterリソースをKubernetesの他のリソースと同じように扱うことができます。たとえば、ラベルを使用してクラスターを担当するチームを識別し、標準のリソースの場合と同様に、これらのクラスターをkubectl get etcdcluster -l team=fooで検索できます。 specフィールドは、このetcdクラスタに関する操作情報が存在する場所です。サポートされているフィールドは多数ありますが、ここでは最も基本的なもののみを示します。versionフィールドには、デプロイする必要があるetcdの正確なバージョンが記述され、replicasフィールドには、存在する必要があるインスタンスの数が記述されます。 例には表示されていないstatusフィールドもあります。このフィールドは、クラスタの現在の状態を説明するためにOperatorが更新します。specフィールドとstatusフィールドの使用はKubernetes APIの標準であり、他のリソースやツールとよく統合されます。 Kubebuilderを使用しているため、これらのカスタムリソース定義の生成に役立つ情報が得られます。Kubebuilderでは、specフィールドとstatusステータスフィールドを定義するGo構造体を作成しています。 type EtcdClusterSpec struct { Version string `json:"version"` Replicas *int32 `json:"replicas"` Storage *EtcdPeerStorage `json:"storage,omitempty"` PodTemplate *EtcdPodTemplateSpec `json:"podTemplate,omitempty"` } このGo構造体、およびstatus同様の構造体から、Kubebuilderは、カスタムリソース定義を生成するためのツールを提供し、これらのリソースを処理するためのハードワークを実装します。これにより、突き合せループ (Reconciler Loop) を処理するためのコードを記述するだけで済みます。 他の言語では、同じことを行うためのサポートが異なる場合があります。Operator用に設計されたフレームワークを使用している場合には、これが生成される可能性があります。たとえば、Rustライブラリkube-deriveは同様の方法で機能します。チームがKubernetes APIを直接使用している場合は、CRDとそのデータを個別に解析するコードを作成する必要があります。 突合せループ etcdクラスタを記述する方法がわかったので、それを実装するリソースを管理するOperatorを構築できます。Operatorはどのように機能することもできますが、ほとんどすべてのOperatorがコントローラパターンを使用します。 コントローラは、「突き合せループ」と呼ばれることが多い単純なソフトウェアループであり、次のロジックを実行します: 望ましい状態を観察します。 管理対象リソースの現在の状態を観察します。 管理対象リソースを目的の状態に合わせるためのアクションを実行します。 KubernetesのOperatorの場合、望ましい状態はリソースのspecフィールド (この例ではEtcdCluster) です。管理対象リソースは、クラスタの内部または外部の何でもかまいません。この例では、ReplicaSets、PersistentVolumeClaims、Servicesなど他のKubneretesリソースを作成します。 特にetcdの場合は、etcdプロセスに直接コンタクトして、管理APIからステータスを取得します。このKubernetes外のアクセスは、ネットワークアクセスの中断がサービスダウンを意味しない可能性があり、少し注意が必要です。これは、etcdが実行されていないことを示すシグナルとして、etcdに接続できないことを使用できないことを意味します (動作中のetcdインスタンスを再起動した場合、ネットワークの停止を悪化させる可能性があります) 。 一般に、Kubernetes API以外のサービスと通信する場合は、可用性または整合性の保証が何であるかを考慮することが重要です。etcdの場合、回答が得られればそれは非常に整合していることがわかりますが、他のシステムはこのように動作しない可能性があります。情報が古くなった結果として誤った行動をとることにより、停止を悪化させないようにすることが重要です。 コントローラの機能 コントローラの最も簡単な設計は、突き合せループを定期的に、たとえば30秒ごとに再実行することです。これは機能しますが、多くの欠点があります。たとえば、2つのループが同時に実行されないように、ループが前回からまだ実行されているかどうかを検出できる必要があります。さらに、これは、30秒ごとに関連するリソースのKubernetesのフルスキャンを意味します。次に、EtcdClusterのインスタンスごとに、関連するPodやその他のリソースを一覧表示する突き合せ機能を実行する必要があります。このアプローチでは、Kubernetes APIに大量の負荷がかかります。 これはまた、非常に「手続き型」のアプローチを促進します。次の突き合せまでに長い時間がかかる可能性があるため、各ループは可能な限り多くのことを実行しようとします。たとえば、一度に複数のリソースを作成します。これは、Operatorが何をすべきかを知るために多くのチェックを実行する必要がある複雑な状態につながる可能性があり、バグが発生する可能性が高くなります。 これに対処するために、コントローラはいくつかの機能を実装します: Kubernetes API監視。 APIキャッシュ。 バッチ更新。 これらすべてを組み合わせると、単一のループを実行するコストと待機する時間が削減されるため、各ループでの実行が効率的になります。その結果、突き合せロジックの複雑さを軽減できます。 API監視 スケジュールに従ってスキャンする代わりに、Kubernetes APIは「監視 (Watch)」をサポートします。APIコンシューマがリソースまたはリソースのクラスへの関心を登録し、一致するリソースが変更されたときに通知を受けることができる場合。これは、Operatorがほとんどの時間アイドル状態でリクエストの負荷を軽減できることを意味し、Operatorが変更にほぼ瞬時に応答することを意味します Operator向けのフレームワークは通常、監視の登録と管理を処理します。 この設計のもう1つの結果は、作成するリソースも監視する必要があるということです。たとえば、Podsを作成する場合は、作成したPodを監視する必要があります。これは、それらが削除された場合、または望ましい状態と一致しないように変更された場合に、通��、ウェイクアップ、および修正できるようにするためです。 その結果、突き合せ機能のシンプルさをさらに一歩進めることができます。たとえば、EtcdClusterに応答して、OperatorはServiceといくつかのEtcdPeerリソースを作成したいと考えています。それらを一度に作成する代わりに、最初にServiceを作成してから終了します。しかし、Services自身を監視しているため、すぐに突き合せするようにトリガされます。その時点で、Peerを作成できます。それ以外の場合は、いくつかのリソースを作成してから、リソースごとに1回ずつ突き合せし、さらに多くの再突き合せをトリガするでしょう。 この設計は、突き合せループを非常に単純に保つのに役立ちます。1つのアクションのみを実行して終了することにより、開発者が考慮すべき複雑な状態の必要性を排除します。 これの主な結果は、更新が見落とされる可能性があることです。ネットワークの中断、Operator Podの再起動、およびその他の問題により、状況によってはイベントの見逃しが発生する場合があります。これに対処するには、Operatorが「エッジベース」ではなく「レベルベース」であるという観点から作業することが重要です。 これらの用語は信号制御ソフトウェアから取られており、信号の電圧に作用することを指します。私たちの世界では、「エッジベース」とは「イベントへの対応」を意味し、「レベルベース」とは「観察された状態への対応」を意味します。 たとえば、リソースが削除された場合、削除イベントを監視し、再作成を選択する場合があります。ただし、削除イベントを見逃した場合は、再作成を試みない可能性があります。また、さらに悪いことに、それがまだ存在していると想定して後で失敗します。代わりに、「レベルベース」のアプローチでは、トリガを単に突き合せする必要があることを示すものとして扱います。外部状態を再度突き合せし、それをトリガした変更の実際のコンテキストを破棄します。 APIキャッシュ 多くのコントローラのもう1つの主要な機能は、リクエストのキャッシュです。突き合せしてPodsを要求し、2秒後に再度トリガすると、2番目のリクエストのキャッシュされた結果が保持される場合があります。これにより、APIサーバの負荷が軽減されますが、開発者にとってはさらに考慮事項があります。 リソースのリクエストは古くなっている可能性があるため、これらを処理する必要があります。特にリソースの作成はキャッシュされないため、次のような状況になる可能性があります: EtcdClusterリソースを突き合せします Serviceを検索しますが、見つかりません。 Serviceを作成して終了します。 作成中のServiceに応じて再突き合せします。 Serviceを検索し、古いキャッシュがヒットしても、表示されません。 Serviceを作成します。 重複するServiceを誤って作成しました。Kubernetes APIはこれを正しく処理し、すでに存在していることを示すエラーを表示します。結果として、このケースを処理する必要があります。一般に、後日、単純にバックオフして再突き合せすることをお勧めします。Kubebuilderでは、突き合せ機能からエラーを返すだけでこれが発生しますが、フレームワークによっては異なる場合があります。後で再実行すると、キャッシュは最終的に整合性が保たれ、突き合せの次のフェーズが発生する可能性があります。 これの1つの副作用は、すべてのリソースに決定論的な名前を付ける必要があることです。そうしないと、重複するリソースを作成する場合、別の名前を使用する可能性があり、実際に重複する可能性があります。 バッチ更新 状況によっては、ほぼ同時に多くの突き合せをトリガする場合があります。たとえば、多数のPodリソースを監視していて、それらの多くが同時に停止している場合 (たとえば、ノード障害、管理者エラーなど) 、複数回通知が届くことが予想されます。ただし、最初の突き合せが実際にトリガされてクラスタの状態が観察されるまでに、すべてのPodはすでになくなっています。したがって、それ以上の突き合せ��必要ありません。 その数が少ない場合、これは問題ではありません。しかし、一度に数百または数千の更新を処理する大規模なクラスタでは、同じ操作を100回続けて繰り返すため、突き合せループのクロールが遅くなったり、キューがいっぱいになってOperatorがクラッシュしたりするリスクがあります。 突き合せ関数は「レベルベース」であるため、これを処理するために最適化を行うことができます。特定のリソースの更新をキューに入れるときに、そのリソースの更新が既にキューにある場合は、そのリソースを削除できます。キューから読み取る前の待機と組み合わせると、操作を効果的に「バッチ処理」できます。したがって、Operatorの正確な条件とそのキュー構成によっては、200個のPodがすべて同時に停止する場合、1回の突き合せのみを実行する可能性があります。 権限 Kubernetes APIにアクセスするすべてのものは、アクセスするための認証情報を提供する必要があります。クラスタ内では、これはPodが実行されるServiceAccountを使用して処理されます。ClusterRoleおよびClusterRoleBindingリソースを使用して、権限をServiceAccountに関連付けることができます。特にOperatorにとって、これは重要です。Operatorには、クラスタ全体で管理するリソースをget、list、およびwatchするための権限が必要です。さらに、それに応じて作成する可能性のあるすべてのリソースに対する幅広い権限が必要になります。たとえば、Pods、StatefulSets、Servicesなど。 KubebuilderやOperator SDKなどのフレームワークは、これらの権限を提供できます。たとえば、Kubebuilderはソースアノテーションアプローチを採用し、コントローラごとに権限を割り当てます。複数のコントローラが1つのデプロイされたバイナリにマージされる場合 (etcd-cluster-operatorの場合のように) 、権限がマージされます。 // +kubebuilder:rbac:groups=etcd.improbable.io,resources=etcdpeers,verbs=get;list;watch // +kubebuilder:rbac:groups=etcd.improbable.io,resources=etcdpeers/status,verbs=get;update;patch // +kubebuilder:rbac:groups=apps,resources=replicasets,verbs=list;get;create;watch // +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims,verbs=list;get;create;watch;delete これは、EtcdPeerリソースの突き合せ用の権限です。独自のリソースをget、list、watchし、サブリソースのステータスをupdateしてpatchを適用できることがわかります。これにより、ステータスのみを更新して、他のユーザに情報を表示することができます。最後に、必要に応じてリソースをcreateおよびdeleteできるように、管理するリソースに対する幅広い権限があります。 検証とデフォルト設定 カスタムリソース自体が一定レベルの検証とデフォルト設定を提供しますが、より複雑なチェックを実行するのはOperatorに任されています。最も簡単なアプローチは、リソースがOperatorに読み込まれたときにそれを行うことです。監視 (watch) から返されたとき、または手動で読んだ直後など。ただし、これは、デフォルトがKubernetesの表示に適用されないことを意味し、管理者の混乱を招く可能性があります。 より良いアプローチは、Webhook構成の検証と変更 (mutating) を使用することです。これらのリソースは、リソースを永続化する前に、リソースが作成、更新、または削除されたときにWebhookを使用する必要があることをKubernetesに通知します。 たとえば、Mutating Webhookを使用してデフォルトを実行できます。Kubebuilderでは、MutatingWebhookConfigurationを作成するための追加の構成をいくつか提供し、KubebuilderはAPIエンドポイントの提供を処理します。私たちが書くのは、デフォルトにするspec構造体のDefaultメソッドだけです。次に、そのリソースが作成されると、リソースが永続化される前にWebhookが呼び出され、デフォルト設定が適用されます。 ただし、リソースの読み取りにデフォルトを適用する必要があります。Operatorは、Webhookが有効になっているかどうかを知るために、プラットフォームについて推測することはできません。たとえそうであっても、構成が誤っているか、ネットワークの停止によりWebhookがスキップされるか、Webhookが構成される前にリソースが適用されている可能性があります。これらの問題はすべて、Webhookがより優れたユーザエクスペリエンスを提供しますが、Operatorコードでは信頼できないため、デフォルト設定を再実行する必要があることを意味します。 テスト ロジックの個々のユニットは、言語の通常のツールを使用してユニットテストできますが、統合テストは特定の問題を引き起こします。APIサーバをモックできる単純なデータベースと考えたくなるかもしれません。ただし、実際のシステムでは、APIサーバは多くの検証とデフォルト設定を実行します。これは、テストと実際の動作が異なる可能性があることを意味します。 大雑把に言えば、2つの主要なアプローチがあります: 最初のアプローチでは、テストハーネスがkube-apiserverおよびetcd実行可能ファイルをダウンロードして実行し、実際に機能するAPIサーバを作成します (ここでのetcdの使用は、サンプルOperatorがetcdを管理しているという事実とは関係ありません) 、もちろん、ここにPodsを作成するKubernetesコンポーネントがないReplicaSetを作成することもできます。そのため、実際には何も実行されません。 2番目のアプローチははるかに包括的で、実際のKubernetesクラスタを使用します。Podsを実行でき、正しく応答します。この種の統合テストは、kindを使用するとはるかに簡単になります。このプロジェクトは、「DockerのKubernetes」の短縮形であり、Dockerコンテナを実行できる場所であればどこでも完全なKubernetesクラスタを実行できます。APIサーバがあり、Podsを実行でき、すべての主なKubernetesツールを実行します。その結果、kindを使用するテストは、ラップトップまたはCIで実行でき、Kubernetesクラスタのほぼ完全な振る舞いを提供します。 結びにあたって この記事では多くのアイデアに触れましたが、最も重要なアイデアは次のとおりです: Operatorを、操作するのと同じクラスタにPodsとしてデプロイします。 どの言語でもかまいませんので、チームに最適な言語を選択してください。しかし、Goには最も成熟したエコシステムがあります。 Kubernetes以外のリソース、特にネットワークの停止中や停止を悪化させる可能性のあるアップストリームAPIの障害時の動作に注意してください。 突き合せサイクルごとに1つの操作を実行してから終了し、Operatorが再キューイングできるようにします。 「レベルベース」のアプローチを使用して設計し、突き合せをトリガしたイベントの内容を無視します。 新しいリソースには決定論的な命名を使用します。 サービスアカウントに最小限の権限を付与します。 Webhookとコードでデフォルト設定を実行します。 kindを使用して、ラップトップとCIで実行できる統合テストを作成します。 これらのツールを使用すると、Operatorを構築してデプロイメントを簡素化し、運用チームの負担を軽減できます。独自のアプリケーションでも開発したアプリケーションでも。 著者について James Laverack氏は、英国を拠点とするKubernetesプロフェッショナルサービス会社であるJetstackでソリューションエンジニアとして働いています。7年以上の業界経験を持ち、ほとんどの時間をクラウドネイティブジャーニーで企業を支援することに費やしています。Laverack氏はKubernetesの貢献者でもあり、バージョン 1.18からKubernetesリリースチームに所属しています。
0 notes
masaa-ma · 6 years ago
Text
43種ものデータ変形がブラウザだけでできる『transform』が便利そう
from https://qiita.com/suin/items/04db26b91244fb3cbc8b?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
transformは、なんでもデータ変形サービスで、JSONからYAML、HTMLからJSXへの変形はもちろん、JSONやGraphQLのIDLからTypeScriptのinterfaceを生成するようなものまで手広く対応しているサービスだ。
https://transform.tools/
Tumblr media
特別なツールをインストールする必要はなくブラウザだけで動作する。
現在、43種類のデータ変形に対応しており、対応している変形パターンは下記のとおり:
SVG to JSX
SVG to React Native
HTML to JSX
JSON to React PropTypes
JSON to Flow
JSON to GraphQL
JSON to TypeScript
JSON to MobX-State-Tree Model
JSON to Sarcastic
JSON to io-ts
JSON to Rust Serde
JSON to Mongoose Schema
JSON to Big Query Schema
JSON to MySQL
JSON to Scala Case Class
JSON to Go Struct
JSON to YAML
JSON to JSDoc
JSON Schema
JSON to TypeScript
JSON to OpenAPI Schema
CSS to JS Objects
CSS to template literal
JavaScript to JSON
GraphQL to TypeScript
GraphQL to Flow
GraphQL to JAVA
GraphQL to Resolvers Signature
GraphQL to Introspection JSON
GraphQL to Schema AST
GraphQL to Fragment Matcher
GraphQL to Components
GraphQL to TypeScript MongoDB
JSON-LD to N-Quads
JSON-LD to Expanded
JSON-LD to Compacted
JSON-LD to Flattened
JSON-LD to Framed
JSON-LD to Normalized
Flow to Typescript
XML to JSON
YAML to JSON
Markdown to HTML
どんなときに使うといいか?
例えば
Reactコンポーネントを作っていて、素材となるHTMLをJSXにしたいとき。
JSON APIのレスポンスをTypeScriptで扱う際、レスポンスJSONの型をTypeScriptのinterfaceで定義したいとき
こういったシーンで、手っ取り早く仕事を済ますときに使えそう。
0 notes
kjunichi · 8 years ago
Text
rust - struct <-> String <-> Json - Qiita [はてなブックマーク]
rust - struct <-> String <-> Json - Qiita
"Rust Json" で検索するとrust-lang/rustの serialize::json と rust-lang/rust-serializeの rustc-serialize::json の2つが出てきます。どちらを使えばいいのかと思い調べていたら2015年の1月に Confused between serialize and rustc-serialize というのが立てられていて、...
kjw_junichi あとで読む
from kjw_junichiのブックマーク http://ift.tt/2hWu2ES
0 notes
this-week-in-rust · 3 years ago
Text
This Week in Rust 450
Hello and welcome to another issue of This Week in Rust! Rust is a programming language empowering everyone to build reliable and efficient software. This is a weekly summary of its progress and community. Want something mentioned? Tweet us at @ThisWeekInRust or send us a pull request. Want to get involved? We love contributions.
This Week in Rust is openly developed on GitHub. If you find any errors in this week's issue, please submit a PR.
Updates from Rust Community
Official
Announcing Rust 1.62.0
RLS Deprecation
Project/Tooling Updates
rust-analyzer changelog #136
GCC-Rust Feedback Sought - Possibly Aiming For Upstream In GCC 13
Announcing lettre 0.10 - lettre
The last two years in Miri
Fornjot (code-first CAD in Rust) - Weekly Dev Log - 2022-W26
HexoSynth (modular synthesizer) - Devlog 3 - Chunk of GUI Work
Slint UI crate weekly updates
This week in Databend #49: A Modern Cloud Data Warehouse for Everyone
Observations/Thoughts
C++ & Rust: (Interior) Mutability, Moving and Ownership
More than you've ever wanted to know about errors in Rust
Minimalist Guide to Axum
Insights of porting Hugging Face Rust Tokenizers to WASM
[audio] New Rustacean with Chris Krycho
[video] The Future of Programming Languages
Rust Walkthroughs
mirrord internals - hooking libc functions in Rust and fixing bugs
Pathfinding in Rust: A tutorial with examples
Plantuml encoding in Rust using TDD
A const builder pattern in Rust
STM32F4 Embedded Rust at the HAL: Button Controlled Blinking by Timer Polling
[video] Simple error handling in Rust
[video] Making a Rust crate compile faster
[video] Rust for the impatient
[video] Cph.rs Hack Night - Simon Rasmussen on WASM and WAT the fp-bindgen
[video] Cph.rs Hack Night - David Pedersen on Axum
Miscellaneous
[DE] Rust-Code im Linux-Kernel: Merge steht laut Linus Torvalds ab Linux 5.20 bevor
[DE] Ferris Talk #10: Constant Fun mit Rust – const fn
[DE] Programmiersprache Rust 1.62 kann Kernel für x86-64 bauen
[video] Rust Coming Soon To A Linux Kernel Near You!!
Crate of the Week
This week's crate is coprosize, a (you guessed it) program aiding the study of dinosaur dung.
Thanks to piotr for the self-nomination.
Please submit your suggestions and votes for next week!
Call for Participation
Always wanted to contribute to open-source projects but didn't know where to start? Every week we highlight some tasks from the Rust community for you to pick and get started!
Some of these tasks may also have mentors available, visit the task page for more information.
If you are a Rust project owner and are looking for contributors, please submit tasks here.
Updates from the Rust Project
415 pull requests were merged in the last week
proc_macro/bridge: stop using a remote object handle for proc_macro Punct and Group
diagnostics: structs with new slug syntax
clean up arg mismatch diagnostic, generalize tuple wrap suggestion
improve some inference diagnostics
some borrowck diagnostic fixes
make TAIT behave exactly like RPIT
fix FFI-unwind unsoundness with mixed panic mode
fix ICE for associated constant generics
fix glob import ICE in rustdoc JSON format
fix rust-call ICE in mir-inliner
fix box with custom allocator in miri
miri: allow non-ZST allocations to be adjacent
miri: enable permissive provenance by default
miri: optimizing Stacked Borrows (part 1?): cache locations of tags in a Borrow Stack
miri: add ./miri clippy
miri: allocation tracking: also print size, alignment, kind of the allocation
miri: stacked borrows: add option for recursive field retagging
miri: tweak int2ptr diagnostics
avoid some &str to String conversions with MultiSpan::push_span_label
avoid unnecessary work in finalize_resolutions_in
don't use match-destructuring for derived ops on structs
enable MIR inlining
improve some deriving code and add a test
optimize non-consuming operators
impl<T: AsRawFd> AsRawFd for {Arc, Box}<T>
add fetch_not method on AtomicBool
optimize Vec::insert for the case where index == len
optimise vectored write
fix data race in thread::scope
cargo: don't panic with --offline
rustfmt: allow #[ignore] tests to run in rustfmt's test suite
rustfmt: config_type: add unstable_variant attribute
clippy: add Operators lint pass
clippy: add invalid_utf8_in_unchecked
clippy: add lint explicit_auto_deref take 2
clippy: don't lint while_let_loop when significant drop order would change
clippy: fix ICE in dereference.rs
clippy: fix #[expect] for most clippy lints
clippy: fix direct #[allow] attributes in let_unit_value
clippy: fix false-positive in equatable_if_let
clippy: new_without_default: ignore const generics/lifetime params on fn new
clippy: trivially_copy_pass_by_ref fixes
let rust-analyzer ship on stable, non-preview
rust-analyzer: complete raw identifier with "r#" prefix
rust-analyzer: show witnesses of non-exhaustiveness in missing-match-arm diagnostic
rust-analyzer: implement destructuring assignment
rust-analyzer: fix regressions on assignment expressions
rust-analyzer: fix attribute macros on assoc items being discarded with disabled proc macros
rust-analyzer: fix: extract Function produces duplicate fn names
rust-analyzer: fix: complete enum variants as patterns in pattern path
rust-analyzer: report proc macro errors in expressions correctly as well
Rust Compiler Performance Triage
Overall the week is a small improvement on average, with some benchmarks (particularly in the primary category) showing significant improvements due to the enablement of MIR inlining in #91743. Inlining promises to improve the quality of our generated LLVM IR and make other optimizations more worthwhile, so it's great to see these early results already being quite impactful.
Triage done by @simulacrum. Revision range: baf382e6..880646c
3 Regressions, 6 Improvements, 6 Mixed; 4 of them in rollups 46 artifact comparisons made in total
See full report for details
Call for Testing
An important step for RFC implementation is for people to experiment with the implementation and give feedback, especially before stabilization. The following RFCs would benefit from user testing before moving forward:
No RFCs issued a call for testing this week.
If you are a feature implementer and would like your RFC to appear on the above list, add the new call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
Approved RFCs
Changes to Rust follow the Rust RFC (request for comments) process. These are the RFCs that were approved for implementation this week:
No RFCs were approved this week.
Final Comment Period
Every week the team announces the 'final comment period' for RFCs and key PRs which are reaching a decision. Express your opinions now.
RFCs
No RFCs entered Final Comment Period this week.
Tracking Issues & PRs
[disposition: merge] Make outlives::{components,verify} agree
[disposition: merge] Enforce that layout size fits in isize in Layout
[disposition: merge] Tracking Issue for feature(core_c_str) and feature(alloc_c_string)
[disposition: merge] Remove restrictions on compare-exchange memory ordering.
[disposition: merge] Partially stabilize const_slice_from_raw_parts
[disposition: merge] Implement network primitives with ideal Rust layout, not C system layout
[disposition: merge] Tracking Issue for feature future_poll_fn
[disposition: merge] Stabilize const-weak-new
[disposition: merge] stabilise mixed_integer_ops
[disposition: merge] Implement fmt::Write for OsString
[disposition: merge] Tracking Issue for process_set_process_group
New and Updated RFCs
[new] Don't allow unwinding from Drop impls
[new] RFC: Add native code coverage support in Cargo
Upcoming Events
Rusty Events between 2022-07-06 - 2022-08-03 🦀
Virtual
2022-07-06 | Indianapolis, IN, US | Indy Rust
Indy.rs - with Social Distancing
2022-07-07 | Charlottesville, VA, US | Charlottesville Rust Meetup
Rust, nalgebra, and Fourier Optics
2022-07-09 | Virtual | Rust Game Dev
Monthly Meetup
2022-07-11 | Minneapolis, MN, US | Minneapolis Rust Meetup
Rust Meetup - "Lifetimes" and Social Hour
2022-07-12 | Dallas, TX, US | Dallas Rust
Second Tuesday
2022-07-12 | Munich, DE | Rust Munich
Rust Munich 2022 / 2 - hybrid
2022-07-13 | Boulder, CO, US | Boulder Elixir and Rust
Monthly Meetup
2022-07-13 | Malaysia, MY | Rust Malaysia Meetup
Rust Malaysia Meetup
2022-07-14 | Nürnberg, DE | Rust Nurnberg DE
Rust Nürnberg online
2022-07-16 | Vancouver, BC, CA | Vancouver Rust
Rust Study/Hack/Hang-out
2022-07-19 | Sydney, NSW, AU | Rust Australia
Rust Lightning Talks
2022-07-19 | Washington, DC, US | Rust DC
Mid-month Rustful
2022-07-21 | Stuttgart, DE | Rust Community Stuttgart
Rust-Meetup
2022-07-26 | Dallas, TX, US | Dallas Rust
Last Tuesday
2022-07-29 | Minneapolis, MN, US | Minneapolis Rust Meetup
Beginner Rust Open "Office Hours"
2022-07-31 | Seattle, WA, US | Seattle Rust Meetup
Intro to Monads for Rustaceans
2022-08-02 | Buffalo, NY, US | Buffalo Rust Meetup
Buffalo Rust User Group, First Tuesdays
2022-08-03 | Indianapolis, IN, US | Indy Rust
Indy.rs - with Social Distancing
2022-08-03 | Stuttgart, DE | Rust Community Stuttgart
Rust-Meetup
Europe
2022-07-06 | Paris, FR | Stockly
Rust Meetup in Paris
2022-07-12 | Munich, DE | Rust Munich
Rust Munich 2022 / 2 - hybrid
North America
2022-07-11 | Minneapolis, MN, US | Minneapolis Rust Meetup
Rust Meetup - "Lifetimes" and Social Hour
2022-07-13 | Atlanta, GA, US | Rust Atlanta
Grab a beer with fellow Rustaceans
2022-07-14 | Columbus, IL | Columbus Rust Society
Monthly Meeting
2022-07-19 | San Francisco, CA, US | San Francisco Rust Study Group
Rust Hacking in Person
2022-07-26 | Austin, TX, US | ATX Rustaceans
First Official Meetup - July 2022
Oceania
2022-07-28 | Brisbane, QLD, AU | Rust Brisbane
July Meetup
If you are running a Rust event please add it to the calendar to get it mentioned here. Please remember to add a link to the event too. Email the Rust Community Team for access.
Jobs
Please see the latest Who's Hiring thread on r/rust
Tweet us at @ThisWeekInRust to get your job offers listed here!
Quote of the Week
TIL: #cargo has build-in aliases for some commands
so next time try out
cargo r cargo b cargo t
– @5422m4n on twitter
llogiq is pretty pleased with his choice.
Please submit quotes and vote for next week!
This Week in Rust is edited by: nellshamrell, llogiq, cdmistman, ericseppanen, extrawurst, andrewpollack, U007D, kolharsam, joelmarcey, mariannegoldin.
Email list hosting is sponsored by The Rust Foundation
Discuss on r/rust
0 notes
this-week-in-rust · 2 years ago
Text
This Week in Rust 479
Hello and welcome to another issue of This Week in Rust! Rust is a programming language empowering everyone to build reliable and efficient software. This is a weekly summary of its progress and community. Want something mentioned? Tag us at @ThisWeekInRust on Twitter or @ThisWeekinRust on mastodon.social, or send us a pull request. Want to get involved? We love contributions.
This Week in Rust is openly developed on GitHub. If you find any errors in this week's issue, please submit a PR.
Updates from Rust Community
Official
Officially announcing the types team
Diversifying our Content Delivery Networks
Foundation
Lars Bergstrom Elected as Rust Foundation Board of Directors Chair
Join the Rust Foundation at Rust Nation UK 2023
Newsletters
Project/Tooling Updates
rust-analyzer changelog #165
hyper-ish 2022 in review
Mobc 0.8.1 release with improved stability
Zenoh 0.7.0, a pure Rust Pub/Sub/Query protocol for cloud-to-thing continuum, was released and it is packed with new features.
Fornjot (code-first CAD in Rust) - Weekly Release
Slint 0.3.4 release
Astra: A Blocking HTTP Server Built on Top of Hyper
First steps with NGenate - A dataflow and visual programming platform built with rust
toml vs toml_edit
This Week in Fyrox #11
The year 2022 in Dimforge and our objectives for 2023
Observations/Thoughts
Rust in 2023: Growing up
The State of Developer Ecosystem 2022 in Rust: Discover recent trends
The size of Rust Futures
Capability-Safety I: Prelude
Surprises in the Rust JSON Ecosystem
The Git source code audit, viewed as a Rust programmer
Turning a Rust struct into an enum is not always a major breaking change
14 Rust Tools for Linux Terminal Dwellers
[audio] Rust Magazine with Shuang Zhu
[audio] Rust Nation with Ernest Kissiedu
Rust Walkthroughs
Temporary Values, Borrowing, and Lifetimes
Due to limitations in the borrow checker, this implies a 'static lifetime
Rust concepts I wish I learned earlier
Comparative fuzzing in Rust
domain-specific error macros
Building a Simple DB in Rust - Part 2 - Basic Execution
Rust FFI and cbindgen: Integrating Embedded Rust Code in C
Research
Miscellaneous
The crates.io registry is now a GitHub secret scanning integrator
Six fun things to do with Rust operator overloading
Packaging Rust Applications for the NPM Registry
Announcing Rust Support in CodeSandbox
[video] 10 Reasons Not To Use Rust (The Whole Truth)
[video] Sneaking By The Rust Borrow Checker - Interior Mutability
Crate of the Week
This week's crate is Darkbird, a mnesia-inspired high concurrency, real time, in-memory storage library.
Thanks to DanyalMh for the self-suggestion!
Please submit your suggestions and votes for next week!
Call for Participation
Always wanted to contribute to open-source projects but did not know where to start? Every week we highlight some tasks from the Rust community for you to pick and get started!
Ockam - Implement 'ockam node logs' CLI command
Ockam - Implement 'ockam worker list' CLI command
Ockam - Add a CI check to avoid conflicts in 'TypeTag' ids
If you are a Rust project owner and are looking for contributors, please submit tasks here.
Updates from the Rust Project
378 pull requests were merged in the last week
llvm-wrapper: adapt for LLVM API change
enable sanitizers for s390x-linux
put noundef on all scalars that don't allow uninit
add 'static lifetime suggestion when GAT implied 'static requirement from HRTB
add raw identifier for keyword in suggestion
check ADT fields for copy implementations considering regions
constify TypeId ordering impls
diagnostics: suggest changing s@self::{macro}@::macro for exported
dont randomly use _ to print out const generic arguments
drop tracking Visit break expressions
encode const mir for closures if they're const
fix check macro expansion
label closure captures/generator locals that make opaque types recursive
lazy dominator tree construction in borrowck
make CastError::NeedsDeref create a MachineApplicable suggestion
make error emitted on impl &Trait nicer
refactor basic blocks control flow caches
simplify derive(Debug) output for fieldless enums
suggest remove deref for type mismatch
suggestion for attempted integer identifier in patterns
tweak "borrow closure argument" suggestion
unify stable and unstable sort implementations in same core module
use UnordMap and UnordSet for id collections (DefIdMap, LocalDefIdMap, etc)
various cleanups around pre-TyCtxt queries and functions
add heapsort fallback in select_nth_unstable
implement alloc::vec::IsZero for Option<$NUM> types
lift T: Sized bounds from some strict_provenance pointer methods
add Arc::into_inner for safely discarding Arcs without calling the destructor on the inner type
hashbrown: provide default hasher types to Vacant and Occupied entries
futures: add Either::as_pin_mut and Either::as_pin_ref
futures: implement FusedStream for all streams in ReadyChunks
(cherry-pick) WebAssembly multivalue stackify fix
cargo: stabilize sparse-registry
cargo: wrapper type for data that should never be logged
rustfmt: correct span for structs with const generics
clippy: add multiple_unsafe_ops_per_block lint
clippy: add machine applicable suggestion for bool_assert_comparison
clippy: fix false positive in unnecessary_safety_comment
clippy: fix suggestion in transmutes_expressible_as_ptr_casts when the source type is a borrow
rust-analyzer: don't escape non-snippets in assist
rust-analyzer: don't respond with a ContentModified while loading the workspace
rust-analyzer: fix checkOnSave to check config patching not always working
rust-analyzer: fix markdown removal in hover handling whitespace weirdly
rust-analyzer: handle slice patterns in "Fill match arms"
rust-analyzer: more precise binop inference
rust-analyzer: substitute vscode variables in config.serverPath
rust-analyzer: parse const_closures syntax
rust-analyzer: replace SmolStr usage with lang item enum for lang items
rust-analyzer: use workspace.dependencies to declare local dependencies
Rust Compiler Performance Triage
Largely a win for compiler performance with 100 test cases in real-world crates showing some sort of change in performance with an average 1% improvement. These wins were a combination of many different changes including how doc(hidden) gets more efficiently encoded in metadata, some optimizations in the borrow checker, and simplification of the output from derive(Debug) for fieldless enums.
Triage done by @rylev. Revision range: 1f72129f..c8e6a9e8
Summary:
(instructions:u) mean range count Regressions ❌ (primary) 0.4% [0.2%, 0.7%] 19 Regressions ❌ (secondary) 0.9% [0.2%, 1.5%] 34 Improvements ✅ (primary) -1.3% [-17.2%, -0.2%] 81 Improvements ✅ (secondary) -2.1% [-7.1%, -0.2%] 64 All ❌✅ (primary) -1.0% [-17.2%, 0.7%] 100
2 Regressions, 5 Improvements, 3 Mixed; 1 of them in rollups 34 artifact comparisons made in total
Full report here
Approved RFCs
Changes to Rust follow the Rust RFC (request for comments) process. These are the RFCs that were approved for implementation this week:
No RFCs were approved this week.
Final Comment Period
Every week, the team announces the 'final comment period' for RFCs and key PRs which are reaching a decision. Express your opinions now.
RFCs
No RFCs entered Final Comment Period this week.
Tracking Issues & PRs
[disposition: merge] Autotrait bounds on dyn-safe trait methods
[disposition: close] Stabilize ControlFlow::{BREAK, CONTINUE}
[disposition: merge] Add missing normalization for union fields types
[disposition: merge] rustdoc: change trait bound formatting
New and Updated RFCs
[new] Cargo target features
[new] Avoid non-local definitions in functions
Call for Testing
An important step for RFC implementation is for people to experiment with the implementation and give feedback, especially before stabilization. The following RFCs would benefit from user testing before moving forward:
No RFCs issued a call for testing this week.
If you are a feature implementer and would like your RFC to appear on the above list, add the new call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
Upcoming Events
Rusty Events between 2023-01-25 - 2023-02-22 🦀
Virtual
2023-01-25 | Virtual (Redmond, WA, US; San Francisco, CA, US) | Microsoft Reactor Redmond | Microsoft Reactor San Francisco
Primeros pasos con Rust: QA y horas de comunidad | San Francisco Mirror
2023-01-26 | Virtual (Charlottesville, VA, US) | Charlottesville Rust Meetup
Rust Lightning Talks!
2023-01-26 | Virtual (Karlsruhe, DE) | The Karlsruhe Functional Programmers Meetup Group
Stammtisch (gemeinsam mit der C++ UG KA)
2023-01-26 | Virtual (Redmond, WA, US; San Francisco, CA, US; New York, NY, US; Stockholm, SE) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco and Microsoft Reactor Stockholm
Crack code interview problems in Rust - Ep. 3 | New York Mirror | San Francisco Mirror | Stockholm Mirror
2023-01-27 | Virtual (Tunis, TN) | Rust Meetup Tunisia
Rust Meetup Tunisia - Volume I, Number I
2023-01-30 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Control de errores en Rust | New York Mirror | San Francisco Mirror
2023-01-31 | Virtual (Berlin, DE) | OpenTechSchool Berlin
Rust Hack and Learn
2023-01-31 | Virtual (Dallas, TX, US) | Dallas Rust
Last Tuesday
2023-01-31 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Compresión de cómo Rust administra la memoria | New York Mirror | San Francisco Mirror
2023-02-01 | Virtual (Cardiff, UK) | Rust and C++ Cardiff
New Year Virtual Social + Share
2023-02-01 | Virtual (Indianapolis, IN, US) | Indy Rust
Indy.rs - with Social Distancing
2023-02-01 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco
Primeros pasos con Rust: QA y horas de comunidad | New York Mirror | San Francisco Mirror
2023-02-01 | Virtual (Stuttgart, DE) | Rust Community Stuttgart
Rust-Meetup
2023-02-06 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Implementación de tipos y rasgos genéricos | New York Mirror | San Francisco Mirror
2023-02-07 | Virtual (Beijing, CN) | WebAssembly and Rust Meetup (Rustlang)
Monthly WasmEdge Community Meeting, a CNCF sandbox WebAssembly runtime
2023-02-07 | Virtual (Buffalo, NY, US) | Buffalo Rust Meetup
Buffalo Rust User Group, First Tuesdays
2023-02-07 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Reactor New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Módulos, paquetes y contenedores de terceros | New York Mirror | San Francisco Mirror
2023-02-08 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Rector New York and Microsoft Reactor San Francisco
Primeros pasos con Rust: QA y horas de comunidad | New York Mirror | San Francisco Mirror
2023-02-11 | Virtual | Rust GameDev
Rust GameDev Monthly Meetup
2023-02-13 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Rector New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Escritura de pruebas automatizadas | New York Mirror | San Francisco Mirror
2023-02-14 | Virtual (Berlin, DE) | OpenTechSchool Berlin
Rust Hack and Learn
2023-02-14 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US) | Microsoft Reactor Redmond and Microsoft Rector New York and Microsoft Reactor San Francisco
Primeros pasos con Rust - Creamos un programa de ToDos en la línea de comandos | San Francisco Mirror | New York Mirror
2023-02-14 | Virtual (Saarbrücken, DE) | Rust-Saar
Meetup: 26u16
2023-02-15 | Virtual (Redmond, WA, US; New York, NY, US; San Francisco, CA, US; São Paulo, BR) | Microsoft Reactor Redmond and Microsoft Rector New York and Microsoft Reactor San Francisco and Microsoft Reactor São Paulo
Primeros pasos con Rust: QA y horas de comunidad | San Francisco Mirror | New York Mirror | São Paulo Mirror
2023-02-15 | Virtual (Vancouver, BC, CA) | Vancouver Rust
Rust Study/Hack/Hang-out
Asia
2023-02-01 | Kyoto, JP | Kansai Rust
Rust talk: How to implement Iterator on tuples... kind of
Europe
2023-01-25 | Paris, FR | Rust Paris
Rust Paris meetup #55
2023-01-26 | Copenhagen, Dk | Copenhagen Rust Meetup Group
Rust Hack Night #32
2023-02-02 | Berlin, DE | Prenzlauer Berg Software Engineers
PBerg engineers - inaugural meetup; Lukas: Serverless APIs using Rust and Azure functions (Fee)
2023-02-02 | Hamburg, DE | Rust Meetup Hamburg
Rust Hack & Learn February 2023
2023-02-02 | Lyon, FR | Rust Lyon
Rust Lyon meetup #01
2023-02-04 | Brussels, BE | FOSDEM
FOSDEM 2023 Conference: Rust devroom
2023-02-21 | Zurich, CH | Rust Zurich
Practical Cryptography - February Meetup (Registration opens 7 Feb 2023)
North America
2023-01-26 | Lehi, UT, US | Utah Rust
Building a Rust Playground with WASM and Lane and Food!
If you are running a Rust event please add it to the calendar to get it mentioned here. Please remember to add a link to the event too. Email the Rust Community Team for access.
Jobs
Please see the latest Who's Hiring thread on r/rust
Quote of the Week
Rust has demonstrated that you using a type system as a vehicle for separation logic works, even in imperative languages, and it's nothing as arcane as those immutable functional predecessors would suggest. It did this by making sure the language defines a type system that helps you, by making sure core properties of soundness can be expressed in it.
soundness requirement for memory access: lifetimes
soundness requirements for references with value semantics: > &/&mut _
soundness requirements for resources: Copy and Drop
making sure your logic is monotic: traits instead of inheritance, lack of specialization (yes, that's a feature).
(notably missing: no dependent types; apparently not 'necessary' but I'm sure it could be useful; however, research is heavily ongoing; caution is good)
This allows the standard library to encode all of its relevant requirements as types. And doing this everywhere is its soundness property: safe functions have no requirements beyond the sum of its parameter type, unsafe functions can. Nothing new or special there, nothing that makes Rust's notion of soundness special.
Basing your mathematical reasoning on separation logic makes soundness reviews local instead of requiring whole program analysis. This is what makes it practical. It did this pretty successfully and principled, but did no single truly revolutionary thing. It's a sum of good bits from the last decade of type system research. That's probably why people refer to it as 'the soundness definition', it's just a very poignant way to say: "we learned that a practical type systems works as a proof checker".
– HeroicKatora on /r/cpp
Thanks to Stephan Sokolow for the suggestion!
Please submit quotes and vote for next week!
This Week in Rust is edited by: nellshamrell, llogiq, cdmistman, ericseppanen, extrawurst, andrewpollack, U007D, kolharsam, joelmarcey, mariannegoldin, bennyvasquez.
Email list hosting is sponsored by The Rust Foundation
Discuss on r/rust
0 notes
this-week-in-rust · 2 years ago
Text
This Week in Rust 499
Hello and welcome to another issue of This Week in Rust! Rust is a programming language empowering everyone to build reliable and efficient software. This is a weekly summary of its progress and community. Want something mentioned? Tag us at @ThisWeekInRust on Twitter or @ThisWeekinRust on mastodon.social, or send us a pull request. Want to get involved? We love contributions.
This Week in Rust is openly developed on GitHub and archives can be viewed at this-week-in-rust.org. If you find any errors in this week's issue, please submit a PR.
Updates from Rust Community
Foundation
2023 Rust Foundation Fellowship Application Open Through June 30
Project/Tooling Updates
Fyrox Game Engine 0.30
Announcing Nickel 1.0
rust-analyzer changelog #185
Announcing Zebra 1.0.0: a Rust implementation of Zcash
Observations/Thoughts
Iterating on Testing in Rust
Higher-ranked projections (send bound problem, part 4)
[video] Raph Levien on Xilem Vector Graphics
[video] Unsafe Rust and Miri by Ralf Jung
[audio] Slint 1.0 with Tobias Hunger
Rust Walkthroughs
A Beginner’s Guide to Rust Procedural Macros: Creating a JSON Derive Macro
Implementing data parallelism with Rayon Rust
Write a Redux library in Rust
Check AI-Generated Code Perfectly and Automatically: My Experience Applying Kani’s Formal Verification to ChatGPT-Suggested Rust Code
Observing your Rust application with Quickwit, Jaeger and Grafana
[video] Introducing the enum data type in Rust
[video] Rust streams: Diving into WebAssembly and WASI (series)
Crate of the Week
This week's crate is mailtutan, a simulating SMTP server.
Thanks to Mohsen Alizadeh for the self-suggestion!
Please submit your suggestions and votes for next week!
Call for Participation
Always wanted to contribute to open-source projects but did not know where to start? Every week we highlight some tasks from the Rust community for you to pick and get started!
Some of these tasks may also have mentors available, visit the task page for more information.
Send File - help improve the readme
Send File - create wifi hotspot on Linux operating system
Send File - use Tauri store plugin to persist app data
Ockam - Extract command logic from Kafka create commands
Ockam - Enable pnpm support in dependabot
Ockam - Update CLI documentation for credential commands
Hyperswitch - add domain type for client secret
Hyperswitch - Remove Basic keyword from shift4 API key
Hyperswitch - Payments list doesn't work with pagination parameters
If you are a Rust project owner and are looking for contributors, please submit tasks here.
Updates from the Rust Project
346 pull requests were merged in the last week
expand: prevent infinite loop in macro containing only "///"
expand: change how #![cfg(FALSE)] behaves on crate root
add task::Waker::noop
add windows_sys type definitions for ARM32 manually
add deprecation warning to python versions <3.6 in x.py
add help for trying to do C-like pointer arithmetics
add new Tier-3 targets: loongarch64-unknown-none*
added custom risc32-imac for esp-espidf target
adjust span labels for hidden_glob_reexports
avoid ICE on #![doc(test(...)] with literal parameter
avoid passing --cpu-features when empty
avoid unwind across extern "C" in thread_local::fast_local
diagnostics: do not suggest type name tweaks on type-inferred closure args
do fix_*_builtin_expr hacks on the writeback results
don't hold the active queries lock while calling make_query
don't mention already-set fields in struct constructor missing field error
don't suggest changing &self and &mut self in function signature to be mutable when taking &mut self in closure
dont compute opt_suggest_box_span span for TAIT
emit an error when return-type-notation is used with type/const params
ensure space is inserted after keyword in unused_delims
fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal
fix ICE for while loop with assignment condition with LHS place expr
fix suggestion for matching struct with .. on both ends
force all native libraries to be statically linked when linking a static binary
implement stdout streaming in render_tests::Renderer
improved std support for ps vita target
increase the accuracy of effective visibilities calculation
make "consider importing" consistent for macros
make GDB Python Pretty Printers loadable after spawning GDB, avoiding required rust-gdb
merge method, type and const object safety checks
normalize in infcx instead of globally for Option::as_deref suggestion
prevent emitting missing_docs for pub extern crate
private-in-public lints implementation
remember names of cfg-ed out items to mention them in diagnostics
remove default visitor impl in region constraint generation
removed use of iteration through a HashMap/HashSet in rustc_incremental and replaced with IndexMap/IndexSet
resolve vars in result from scrape_region_constraints
respect RUST_BACKTRACE for delayed bugs
structurally resolve pointee in check_pat_lit
suggest using ptr::null_mut when user provided ptr::null to a function expecting ptr::null_mut
take MIR dataflow analyses by mutable reference
uplift clippy::cmp_nan lint
uplift clippy::undropped_manually_drops lint
use load+store instead of memcpy for small integer arrays
write to stdout if - is given as output file
use 128 bits for TypeId hash
support float-like tuple indices in offset_of!()
codegen_gcc: regen intrinsics with latest LLVM version
cargo: initial support for single-file packages
cargo: disable multiplexing for some versions of curl
cargo: fetch nested git submodules
cargo: test: loose overly matches for git cli output
cargo: upgrade to gix v0.45 for multi-round pack negotiations
rustdoc: Fix infinite loop when retrieving impls for type alias
rustdoc: List matching impls on type aliases
rustdoc: search for slices and arrays by type with []
rustfmt: recover comments between attrs and generic param
rustfmt: remove rustc-workspace-hack
clippy: new lints: excessive_nesting, needless_if, unnecessary_literal_unwrap, redundant type annotations, arc_with_non_send_or_sync, min_ident_chars, large_stack_frames
clippy: let_with_type_underscore: Don't emit on locals from procedural macros
clippy: missing_fields_in_debug: don't ICE when self type is a generic param
clippy: redundant_closure: special case inclusive ranges
clippy: suspicious_else_formatting: Don't warn if there is a comment between else and curly bracket
clippy: type_repetition_in_bounds: Don't lint on derived code
clippy: unnecessary_to_owned: check that the adjusted type matches target
clippy: useless_vec: lint vec! invocations when a slice or an array would do
clippy: useless_vec: lint on vec![_] invocations that adjust to a slice
clippy: allow disabling module inception on private modules
clippy: consider autoderef through user-defined Deref in eager_or_lazy
clippy: don't lint as_conversions in proc macros
clippy: extend explicit_iter_loop and explicit_into_iter_loop
clippy: fix diverging_sub_expression not checking body of block
clippy: fix useless_vec suggestion in for _ in vec![..]
clippy: handle exponent without digits in numeric_literal
clippy: ignore more pointer types in unnecessary_cast
clippy: ignore more type aliases in unnecessary_cast
clippy: make cast_possible_wrap work correctly for 16 bit {u,i}size
fix rust-analyzer proc macro server
rust-analyzer: add span to group
rust-analyzer: count query entries in memory usage command
rust-analyzer: inline const as literal
rust-analyzer: fix panic in displaying const trait objects
rust-analyzer: fix panic in displaying unsized structs
rust-analyzer: deduplicate fields and types in completion
rust-analyzer: derive source scope from syntax node to be transformed
rust-analyzer: exclude Markdown injection grammar from .vscodeignore
rust-analyzer: fix ci never running on nightly when proc-macro things change
rust-analyzer: fix panic in format_args expansion
rust-analyzer: fix proc-macro slow test
rust-analyzer: implemeted lifetime transformation fot assists
rust-analyzer: infer return type for async function in generate_function
rust-analyzer: lower const params with a bad id
rust-analyzer: only generate trait bound for associated types in field types
Rust Compiler Performance Triage
Our build pipeline got sped up by PR #112012, which side-steps one of the rustc rebuilds we were suffering with before. (There is further potential speed-up by caching LLVM, as noted by on that PR.) Other than that, various small regressions that are largely noise, as well as one unexpected increase in binary sizes from PR #109005 that we should follow up on.
Triage done by @pnkfelix. Revision range: adc719d7..4bd4e2ea
7 Regressions, 3 Improvements, 5 Mixed; 5 of them in rollups 46 artifact comparisons made in total
Full report here
Approved RFCs
Changes to Rust follow the Rust RFC (request for comments) process. These are the RFCs that were approved for implementation this week:
Return position impl Trait in traits
Final Comment Period
Every week, the team announces the 'final comment period' for RFCs and key PRs which are reaching a decision. Express your opinions now.
RFCs
No RFCs entered Final Comment Period this week.
Tracking Issues & PRs
[disposition: merge] Implement Sync for mpsc::Sender
[disposition: merge] resolve: Remove artificial import ambiguity errors
[disposition: merge] Relax implicit T: Sized bounds on BufReader<T>, BufWriter<T> and LineWriter<T>
New and Updated RFCs
[new] Infered types
Call for Testing
An important step for RFC implementation is for people to experiment with the implementation and give feedback, especially before stabilization. The following RFCs would benefit from user testing before moving forward:
No RFCs issued a call for testing this week.
If you are a feature implementer and would like your RFC to appear on the above list, add the new call-for-testing label to your RFC along with a comment providing testing instructions and/or guidance on which aspect(s) of the feature need testing.
Upcoming Events
Rusty Events between 2023-06-14 - 2023-07-12 🦀
Virtual
2023-06-14 | Virtual (Cardiff, UK) | Rust and C++ Cardiff
Building Spin Locks and Channels - Rust Atomics & Locks Bookclub Chapters 4 & 5
2023-06-14 | Virtual (Boulder, CO, US) | Boulder Elixir and Rust
Monthly Meetup
2023-06-15 | Virtual (Stuttgart, DE) | Rust Community Stuttgart
Rust-Meetup
2023-06-15 | Virtual (Tehran, IR) | Iran Rust Meetup
Iran Rust Meetup #11 - Unsafe and FFI
2023-06-19 | Virtual (San Francisco, CA, US) | Data Science on AWS - San Francisco, Global
Generative AI Parameter Efficient Fine Tuning (PEFT), RLHF + Polars: "Polars, lightning-fast DataFrame library for Rust and Python", presented by Suman Debnath
2023-06-20 | Virtual (Berlin, DE) | Berline.rs / OpenTechSchool Berlin
Rust Hack and Learn
2023-06-20 | Virtual (Washington, DC, US) | Rust DC
Mid-month Rustful
2023-06-21 | Virtual (Vancouver, BC, CA) | Vancouver Rust
Rust Study/Hack/Hang-out
2023-06-22 | Virtual (Karlsruhe, DE) | Karlsruhe Functional Programmers Group
Stammtisch (gemeinsam mit der C++ UG KA)
2023-06-25 | Virtual (Auckland, NZ) | ResBaz Aotearoa 2023
Research Computing With The Rust Programming Language - Tim McNamara
2023-06-27 | Virtual (Dallas, TX, US) | Dallas Rust
Last Tuesday
2023-06-28 | Virtual (Chicago, IL, US) | Chicago Healthcare Cloud Technology Community
Rust for Mission-Critical AI: A Journey into Healthcare's Safest Language
2023-06-29 | Virtual (Ciudad de México, MX) | Rust MX
Rust y Haskell
2023-07-01 | Virtual (Nürnberg, DE) | Rust Nuremberg
Deep Dive Session 4: Protohackers Exercises Mob Coding (Problem II onwards)
2023-07-04 | Virtual (Berlin, DE) | Berline.rs / OpenTechSchool Berlin
Rust Hack and Learn
2023-07-04 | Virtual (Buffalo, NY, US) | Buffalo Rust Meetup
Buffalo Rust User Group, First Tuesdays
2023-07-05 | Virtual (Indianapolis, IN, US) | Indy Rust
Indy.rs - with Social Distancing
2023-07-11 | Virtual (Dallas, TX, US) | Dallas Rust
Second Tuesday
Asia
2023-06-15 | Seoul, KR | T-RUST meetup
🦀 T-RUST Meetup 🦀
Europe
2023-06-16 | Stuttgart, DE | Rust Community Stuttgart
OnSite Meeting
2023-06-20 | Montpellier, FR | Montpellier Rust Meetup
Meetup Rust Juin 2023
2023-06-22 | Vienna, AT | Papers We Love Vienna
June: Data and Ownership in Rust
2023-06-22 | Bern, CH | Rust Bern
Second Rust Bern Meetup
2023-06-22 | Wrocław, PL | Rust Wrocław
Rust Meetup #34
2023-06-27 | London, UK | Rust London User Group
LDN Talks June 2023 Shuttle Takeover
2023-06-27 | Paris, FR | Rust Paris
Rust Paris meetup #60
2023-06-28 | Bratislava, SK | Bratislava Rust Meetup Group
Rust Meetup by Sonalake
2023-06-29 | Augsburg, DE | Rust Meetup Augsburg
Augsburg Rust Meetup
2023-06-29 | Copenhagen, DK | Copenhagen Rust Community
Rust metup #37 at Samsung!
2023-07-01 | Basel, CH | Rust Basel
(Beginner) Rust Workshop
2023-07-03 | Zurich, CH | Rust Zurich
Rust in the Linux Kernel - July Meetup
North America
2023-06-15 | Mountain View, CA, US | Mountain View Rust Meetup
Rust Meetup at Hacker Dojo
2023-06-17 | San Jose, CA, US | Rust Breakfast & Learn
Rust: breakfast & learn
2023-06-20 | San Francisco, CA, US | San Francisco Rust Study Group
Rust Hacking in Person
2023-06-21 | Austin, TX, US | Rust ATX
Rust Lunch - Pizza sponsored by JFrog
2023-06-21 | Somerville, MA, US | Boston Rust Meetup
Ball Square Rust Lunch, June 21
2023-06-22 | New York, NY, US | Rust NYC
Learn How to Use cargo-semver-checks and Closure Traits to Write Better Code
2023-06-24 | San Jose, CA, US | Rust Breakfast & Learn
Rust: breakfast & learn
2023-06-28 | Cambridge, MA, US | Boston Rust Meetup
Harvard Square Rust Lunch
2023-07-01 | San Jose, CA, US | Rust Breakfast & Learn
Rust: breakfast & learn
2023-07-07 | Chicago, IL, US | Deep Dish Rust
Rust Lunch
If you are running a Rust event please add it to the calendar to get it mentioned here. Please remember to add a link to the event too. Email the Rust Community Team for access.
Jobs
Please see the latest Who's Hiring thread on r/rust
Quote of the Week
Alas this week remains quoteless for lack of suggestions.
Please submit quotes and vote for next week!
This Week in Rust is edited by: nellshamrell, llogiq, cdmistman, ericseppanen, extrawurst, andrewpollack, U007D, kolharsam, joelmarcey, mariannegoldin, bennyvasquez.
Email list hosting is sponsored by The Rust Foundation
Discuss on r/rust
0 notes